package com.villaday.idf.fragment;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import com.google.android.material.appbar.AppBarLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.core.widget.NestedScrollView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.ScaleAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.villaday.idf.AppContext;
import com.villaday.idf.MainActivity;
import com.villaday.idf.R;
import com.villaday.idf.activity.BackHandlerHelper;
import com.villaday.idf.activity.BieShuSearchResultActivity;
import com.villaday.idf.activity.BourbonListActivity;
import com.villaday.idf.activity.CashWithdrawalActivity;
import com.villaday.idf.activity.CommissionSettingActivity;
import com.villaday.idf.activity.CustomerBehaviorActivity;
import com.villaday.idf.activity.CustomerListActivity;
import com.villaday.idf.activity.CustomerOrderActivity;
import com.villaday.idf.activity.FissionRedEnvelopeActivity;
import com.villaday.idf.activity.FragmentBackHandler;
import com.villaday.idf.activity.H5Activity;
import com.villaday.idf.activity.H5AutoTitleActivity;
import com.villaday.idf.activity.Home_temaiSearchActivity;
import com.villaday.idf.activity.HouseDetailsActivityFor3;
import com.villaday.idf.activity.IncomeDetailsActivity;
import com.villaday.idf.activity.InviteDownloadActivity;
import com.villaday.idf.activity.InviteFriendActivity;
import com.villaday.idf.activity.InviteLiBaoActivity;
import com.villaday.idf.activity.JDMSBSActivity;
import com.villaday.idf.activity.MinsuSearchResultActivity;
import com.villaday.idf.activity.MyBalanceActivity;
import com.villaday.idf.activity.MyOrderActivity;
import com.villaday.idf.activity.MyOrderDetailActivity;
import com.villaday.idf.activity.MyWineShopActivity;
import com.villaday.idf.activity.PerformanceListActivity;
import com.villaday.idf.activity.SVIPFreeActivity;
import com.villaday.idf.activity.SearchBournActivity;
import com.villaday.idf.activity.SearchMinSu2VActivity;
import com.villaday.idf.activity.ShopActivity;
import com.villaday.idf.activity.SvipEquityActivity;
import com.villaday.idf.activity.SvipSetNameActivity;
import com.villaday.idf.activity.UpgradeVipActivity;
import com.villaday.idf.activity3.JiaFanActivity;
import com.villaday.idf.adapter3.VipDynamicListAdapter;
import com.villaday.idf.adapter3.YaoXinHeadAdapter;
import com.villaday.idf.base.BaseDialog;
import com.villaday.idf.base.BaseFragment;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.custom.AutoScrollViewPager;
import com.villaday.idf.custom.AutoScrollViewPagerVipCanscro;
import com.villaday.idf.custom.BindMobileDialog;
import com.villaday.idf.custom.FillInvitateCodeDialog;
import com.villaday.idf.custom.IncomeIntroduceDialog;
import com.villaday.idf.custom.InvitationCardDialog;
import com.villaday.idf.custom.InvitedFriendDialog;
import com.villaday.idf.custom.LoadingDialog;
import com.villaday.idf.custom.NavView;
import com.villaday.idf.custom.NestedScrollViewCanscro;
import com.villaday.idf.custom.RVItemDecoration;
import com.villaday.idf.custom.SeeRecommerVipDialog;
import com.villaday.idf.custom.UpgradeSvipDialog;
import com.villaday.idf.custom.VipSvipLijiyaoqingDialog;
import com.villaday.idf.custom.pop.HuiYuanMorePop;
import com.villaday.idf.custom.pop.VipYaoqingmashengjiPop;
import com.villaday.idf.model.MaterialRecommendEntity;
import com.villaday.idf.model.MemberUpgradeEntity;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.model.SmsEntity;
import com.villaday.idf.model.VipsNormal;
import com.villaday.idf.model.Vips_invite_buttonsEntity;
import com.villaday.idf.model.advertsCodeEntity;
import com.villaday.idf.model.memberProfitsEntity;
import com.villaday.idf.model.members;
import com.villaday.idf.model2.Global_configurations;
import com.villaday.idf.model2.Merchant_shareEntity;
import com.villaday.idf.model3.MemberConfigurations;
import com.villaday.idf.model3.VipSvipMaterialPosters;
import com.villaday.idf.util.BitMapUtil;
import com.villaday.idf.util.Constant;
import com.villaday.idf.util.JumpUtils;
import com.villaday.idf.util.LogUtil;
import com.villaday.idf.util.LogeUtil;
import com.villaday.idf.util.OkHttpUtil;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;
import com.villaday.idf.util.StatusBarUtil;
import com.villaday.idf.util.ToastUtil;
import com.villaday.idf.util.Utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import byc.imagewatcher.ImageWatcher;
import byc.imagewatcher.MessagePicturesLayout;
import byc.imagewatcher.MessagePicturesLayoutScro;

import static com.bumptech.glide.load.DecodeFormat.PREFER_ARGB_8888;

/**
 * 普通会员
 */
public class OrdinaryVipFragment extends BaseFragment implements FragmentBackHandler, FillInvitateCodeDialog.InvitateCodeListener, OkHttpUtil.OnDataListener, OnClickListener, BaseDialog.OnItemClickListener
        , BindMobileDialog.BindMobileListener, SwipeRefreshLayout.OnRefreshListener, InvitationCardDialog.InvitateCardListener, ImageWatcher.OnPictureLongPressListener, OnAdapterCallbackListener, MessagePicturesLayout.Callback, MessagePicturesLayoutScro.Callback, VipDynamicListAdapter.Callback {

    @BindView(R.id.srf)
    SwipeRefreshLayout swipeRefreshLayout;

    @BindView(R.id.srl_include)
    SwipeRefreshLayout srl_include;


    @BindView(R.id.sv)
    NestedScrollView scrollView;
    @BindView(R.id.rl_ordinary_vip_layout)
    public RelativeLayout rlOrdinaryVip;
    @BindView(R.id.rl_vip_layout)
    public RelativeLayout rlVip;
    @BindView(R.id.rl_svip_layout)
    public RelativeLayout rlSVip;

    @BindView(R.id.sdv_userHead)
    public SimpleDraweeView sdvHead; //普通会员头像
    @BindView(R.id.tv_username)
    public TextView tvNickName;//普通会员昵称

    @BindView(R.id.iv_member_upgrade)
    public TextView tvWriteCode;//填写邀请码
    @BindView(R.id.tv_upgrade)
    public TextView tvUpgrade;//立即升级vip
    @BindView(R.id.ll_save_perchase)
    public LinearLayout llPositionOne;
    @BindView(R.id.ll_promotion)
    public LinearLayout llPositionTwo;
    @BindView(R.id.ll_recommend)
    public LinearLayout llPositionThree;

    @BindView(R.id.sdv_bg)
    public ImageView sdvBg;

    @BindView(R.id.tv_invent_des)
    public TextView tv_invent_des;


    @BindView(R.id.activity_main_app_bar)
    AppBarLayout appBarLayout;

    @BindView(R.id.tv_vip_des)
    TextView tv_vip_des;

    @BindView(R.id.ll_vip_des)
    LinearLayout ll_vip_des;


    /**
     * VipUI
     */
    @BindView(R.id.sdv_vipHead)
    public SimpleDraweeView sdvvipHead;//vip头像
    @BindView(R.id.tv_vipname)
    public TextView tvvipNickName;//vip昵称

    @BindView(R.id.tv_read_more)
    public TextView tvMoreDetails;
    @BindView(R.id.tv_customer_action)
    public TextView tvCustomerBehavior;
    @BindView(R.id.tv_customer_order)
    public TextView tvCustomerOrder;
    @BindView(R.id.ll_custome_layout)
    public LinearLayout llCustomerLayout;

    /**
     * svipUI
     */
    @BindView(R.id.sdv_svipHead)
    public SimpleDraweeView sdvSvipHead;//svip头像
    @BindView(R.id.tv_svipname)
    public TextView tvSvipNickName;//svip昵称

    @BindView(R.id.tv_svipnamefor3)
    public TextView tv_svipnamefor3;//svip昵称


    @BindView(R.id.tv_see_svip_income)
    public TextView tvSvipIncome;//查看svip更多收益
    @BindView(R.id.tv_effective_date)
    public TextView tvOffectiveDate;
    @BindView(R.id.tv_svip_withdrawl_btn)
    public TextView tvWithdraw;
    @BindView(R.id.tv_invitate_code)
    public TextView tvCopyAddress;
    @BindView(R.id.ll_invitate_address)
    public LinearLayout llInvitateCode;


    @BindView(R.id.tv_invitate_code_vip)
    public TextView tvCopyAddressVip;
    @BindView(R.id.ll_invitate_address_vip)
    public LinearLayout llInviteateCodeVip;

    @BindView(R.id.tv_svip_all)
    public TextView tvSvipTotalIncome;//svip累计收益
    @BindView(R.id.tv_svip_month)
    public TextView tvSvipCureentBalance; // svip当前余额
    @BindView(R.id.tv_svip_today)
    public TextView tvSvipTodayIncome; // svip今日收益
    @BindView(R.id.textView_svip_balance)
    public TextView tvSvipBalance;
    @BindView(R.id.tv_svip_can_withdrawl)
    public TextView tvSvipCanWithdrawl;//svip可提现余额
    @BindView(R.id.tv_svip_peoples)
    public TextView tvSvipClient; //svip客户
    @BindView(R.id.tv_svip_level_peoples)
    public TextView tvSvipLowerLevel; //svip我的下级
    @BindView(R.id.tv_vip_effective_date)
    public TextView tvVipOffectiveDate;


    @BindView(R.id.tv_all)
    public TextView tvVipTotalIncome;//Vip累计收益
    @BindView(R.id.tv_month)
    public TextView tvVipCureentBalance; // Vip当前余额
    @BindView(R.id.tv_today)
    public TextView tvVipTodayIncome; // Vip今日收益

    @BindView(R.id.textView_balance)
    public TextView tvVipBalance;//Vip可提现余额
    @BindView(R.id.textView5)
    public TextView tvVipCanWithdrawl;//Vip可提现余额
    @BindView(R.id.tv_peoples)
    public TextView tvVipClient; //Vip客户
    @BindView(R.id.iv_vip_upgrade)
    public TextView tvVipRecommer;
    @BindView(R.id.ll_yqvip)
    public LinearLayout llYqvip;
    @BindView(R.id.tv_vip_level_peoples)
    public TextView tvVipLowerLevel; //svip我的下级

    @BindView(R.id.tv_vipSubTitle1)
    public TextView tv_vipSubTitle1;
    @BindView(R.id.tv_vipTitle1)
    public TextView tv_vipTitle1;
    @BindView(R.id.tv_vipSubTitle)
    public TextView tv_vipSubTitle;
    @BindView(R.id.tv_vipTitle)
    public TextView tv_vipTitle;

    @BindView(R.id.tv_svipSubTitle1)
    public TextView tv_svipSubTitle1;
    @BindView(R.id.tv_svipTitle1)
    public TextView tv_svipTitle1;
    @BindView(R.id.tv_svipSubTitle)
    public TextView tv_svipSubTitle;
    @BindView(R.id.tv_svipTitle)
    public TextView tv_svipTitle;
    @BindView(R.id.ll_fission_red_envelope)
    public LinearLayout llFissionRedEnvelope;
    @BindView(R.id.tv_fission_red_envelope)
    public TextView tvFissionRedEnvelope;
    @BindView(R.id.tv_my_shop)
    public TextView tvMyShop;

    @BindView(R.id.view)
    public View view;

    @BindView(R.id.tv_svip_myShop)//我的店铺
    public TextView tv_svip_myShop;

    @BindView(R.id.ll_top)//顶部广告
    public LinearLayout ll_top;

    //三期
    @BindView(R.id.include)//vip svip
    public View include;
    @BindView(R.id.rl_vip)//普通
    public RelativeLayout rl_vip;

    @BindView(R.id.tv_vip_top)//头部广告位
    public TextView tv_vip_top;

    @BindView(R.id.tv_vip_tixian)//头部提现
    public TextView tv_vip_tixian;

    @BindView(R.id.sdv_vip_head)//头像
    public SimpleDraweeView sdv_vip_head;

    @BindView(R.id.img_vip_type)//角色类别
    public ImageView img_vip_type;

    @BindView(R.id.tv_vip_name)//名字
    public TextView tv_vip_name;

    @BindView(R.id.tv_vip_inventCode)//邀请码
    public TextView tv_vip_inventCode;

    @BindView(R.id.tv_vip_copy)//拷贝
    public TextView tv_vip_copy;

    @BindView(R.id.tv_vip_myStore)//我的店铺
    public TextView tv_vip_myStore;

    @BindView(R.id.tv_vip_svip)//SVIP
    public TextView tv_vip_svip;

    @BindView(R.id.tv_vip_vip)//VIP
    public TextView tv_vip_vip;

    @BindView(R.id.tv_vip_fans)//粉丝
    public TextView tv_vip_fans;

    @BindView(R.id.tv_vip_yongjin)//加返佣金
    public TextView tv_vip_yongjin;

    @BindView(R.id.tv_vip_tixian1)//提现
    public TextView tv_vip_tixian1;

    @BindView(R.id.img_vip_yaoqing)//邀请
    public ImageView img_vip_yaoqing;

    @BindView(R.id.tv_vip_balance)//余额
    public TextView tv_vip_balance;

    @BindView(R.id.tv_vip_leiji)//累计收入
    public TextView tv_vip_leiji;

    /*@BindView(R.id.tv_vip_liebian)//裂变红包
    public TextView tv_vip_liebian;

    @BindView(R.id.ll_vip_shouyidetical)//收益明细
    public LinearLayout ll_vip_shouyidetical;

    @BindView(R.id.tv_vip_ketixiannum)//可提金额
    public TextView tv_vip_ketixiannum;*/

    @BindView(R.id.tv_vip_tixian2)//立即提现
    public TextView tv_vip_tixian2;

   /* @BindView(R.id.tv_vip_tuanduinum)//团队管理
    public TextView tv_vip_tuanduinum;

    @BindView(R.id.tv_vip_lijichakan)//立即查看
    public TextView tv_vip_lijichakan;*/

    @BindView(R.id.tv_vip_dingdan)//客户订单
    public TextView tv_vip_dingdan;
    @BindView(R.id.tv_vip_kehuxingwei)//客户行为
    public TextView tv_vip_kehuxingwei;
    @BindView(R.id.tv_vip_yejiliebiao)//业绩列表
    public TextView tv_vip_yejiliebiao;
    @BindView(R.id.tv_vip_fenyongshezhi)//分佣设置
    public TextView tv_vip_fenyongshezhi;
    @BindView(R.id.view_fenyongshezhi)//分佣设置
    public View view_fenyongshezhi;


    @BindView(R.id.vp_homeAd)
    AutoScrollViewPagerVipCanscro viewPager;
    @BindView(R.id.nv_homeAd)
    NavView navView;

    @BindView(R.id.rv_comments)
    RecyclerView rv_comments;


    @BindView(R.id.ll_bg1)
    LinearLayout ll_bg1;

    @BindView(R.id.ll_vip_svip)
    LinearLayout ll_vip_svip;

    @BindView(R.id.nsv)
    NestedScrollViewCanscro nsv;

    @BindView(R.id.tv_title)
    TextView tv_title;

    ImageView img;//邀请专区
    LinearLayout ll_yaoxin_head;//邀请专区

    RecyclerView rv_yaoxin_head;//邀请专区


    @BindView(R.id.ll_vip_yongjin)
    LinearLayout ll_vip_yongjin;//邀请专区

    @BindView(R.id.ll_gysgl)
    LinearLayout ll_gysgl;//供应商管理
    //邀新专区
            TextView tv_head_des;
    //邀新专区
            View view_head;


    public boolean isClickYXZQneedReflash = false;
    private int mark = -1;

    private int pageNo = 1;
    private int nextIndex = 1;
    private int pageSize = 10;

    //邀新专区  数据
    private List<MaterialRecommendEntity.BodyEntity.DataListEntity> data = new ArrayList<>();
    private ImageWatcher vImageWatcher;

    /**
     * 用于判断是否是升级Vip成功之后来检测是否绑定手机号
     * 还是选择立即提现来检测是否绑定手机号
     */
    private boolean isUpgradeVip;


    private FillInvitateCodeDialog fillInvitateCodeDialog;
    private BindMobileDialog bindMobileDialog;
    private Gson gson = new GsonBuilder().create();
    private LoadingDialog loadingDialog;
    private RefreshtokenEntity refreshtoken;

    private String totalIncmome;

    InvitedFriendDialog invitedFriendDialog;
    private VipsNormal vipsNormal;
    private boolean isneewReflash;

    memberProfitsEntity mp2;
    private Merchant_shareEntity merchant_shareEntity;

    advertsCodeEntity AEntity;
    private VipMidAdvAdapter vipMidAdvAdapter;
    private VipDynamicListAdapter dynamicListAdapter;
    private List<MemberConfigurations.BodyBean.HeaderAdvertsBean> headerAdverts;
    private ScaleAnimation animation;
    private YaoXinHeadAdapter yaoXinHeadAdapter;
    private View inflate;

    public static OrdinaryVipFragment instance() {
        OrdinaryVipFragment findFragment = new OrdinaryVipFragment();
        return findFragment;
    }


    @Override
    protected int getViewResId() {
        return R.layout.fragment_ordinary_vip;
    }

    @Override
    protected void init(View v) {
// 以view中心为缩放点，由初始状态放大两倍
        animation = new ScaleAnimation(
                1.0f, 0.9f, 1.0f, 0.9f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setRepeatCount(-1);
        animation.setDuration(1000);
        animation.setInterpolator(new LinearInterpolator());
        animation.setFillBefore(true);
        animation.setRepeatMode(Animation.REVERSE);
        img_vip_yaoqing.setAnimation(animation);
        StatusBarUtil.setTranslucentForImageViewInFragment(getActivity(), null);
        StatusBarUtil.setLightMode(getActivity());


        appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {

                if (verticalOffset >= 0) {
                    srl_include.setEnabled(true);
                } else {
                    srl_include.setEnabled(false);
                }
            }
        });


        setOnclick();
        if (scrollView != null) {
            scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
                @Override
                public void onScrollChange(NestedScrollView nestedScrollView, int i, int i1, int i2, int i3) {
                    if (swipeRefreshLayout != null) {
                        swipeRefreshLayout.setEnabled(scrollView.getScrollY() == 0);
                    }
                }
            });/*getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                    if (swipeRefreshLayout != null) {
                        swipeRefreshLayout.setEnabled(scrollView.getScrollY() == 0);
                    }
                }
            });*/
        }
        srl_include.setOnRefreshListener(this);
        swipeRefreshLayout.setOnRefreshListener(this);
        if (mark != -1) {
            tvWriteCode.performClick();
            mark = -1;
        }
    }

    private void setOnclick() {
        //普通会员
        tvWriteCode.setOnClickListener(this);
        tvUpgrade.setOnClickListener(this);

        //Vip会员
        tvMoreDetails.setOnClickListener(this);
        tvCustomerBehavior.setOnClickListener(this);
        tvCustomerOrder.setOnClickListener(this);
        llCustomerLayout.setOnClickListener(this);

        //SVIP会员
        tvSvipIncome.setOnClickListener(this);
        tvWithdraw.setOnClickListener(this); //立即提现
        tvSvipNickName.setOnClickListener(this);
        tv_svipnamefor3.setOnClickListener(this);
    }

    @Override
    protected void loadData() {
        loadingDialog = LoadingDialog.newInstance("加载中...");
        loadingDialog.show(getActivity().getFragmentManager());
        getData();


    }

    //是否显示我的店铺
    private void isShowShop() {


        OkHttpUtil.getJSON(getActivity(), Constant.URL.merchant_share, this);

    }

    @Override
    public void onResume() {
        if (isneewReflash) {
            loadData();
            isneewReflash = false;
        } else if (isClickYXZQneedReflash) {
            Map<String, String> map = new HashMap<>();
            //GET 开发完成 /modules/member/configurations 会员中心配置
            OkHttpUtil.getJSON(getContext(), Constant.URL.modules_member_configurations, map, this);
        }

        super.onResume();

    }

    private void getVip() {
        OkHttpUtil.getJSON(getContext(), Constant.URL.vips_normal, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                if (!TextUtils.isEmpty(json)) {
                    LogeUtil.e("vips_normal", json);
                    vipsNormal = gson.fromJson(json, VipsNormal.class);
                    if (Constant.Strings.SUC.equals(vipsNormal.getCode())) {
                        tvUpgrade.setText(vipsNormal.getBody().getBtn().getName());
                        RequestOptions options = new RequestOptions()
                                .placeholder(R.drawable.ic_replace)
                                .error(R.drawable.ic_replace)
                                .priority(Priority.HIGH)
                                .format(PREFER_ARGB_8888)
                                .centerCrop();

//获取图片真正的宽高
                        //获取图片真正的宽高
                        Glide.with(getContext())
                                .asBitmap()//强制Glide返回一个Bitmap对象
                                .load(vipsNormal.getBody().getImageUrl())
                                .apply(options)
                                .into(new SimpleTarget<Bitmap>() {
                                    @Override
                                    public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {


                                        int width = resource.getWidth();
                                        int height = resource.getHeight();
                                        sdvBg.getLayoutParams().width = PhoneUtil.getPhoneWidth(getContext());

                                        sdvBg.getLayoutParams().height = PhoneUtil.getPhoneWidth(getContext()) * height / width;
                                        sdvBg.requestLayout();
                                        sdvBg.setImageBitmap(resource);
                                    }


                                });
                    }
                }
            }

            @Override
            public void onFailure(String url, String error) {

            }
        });
    }

    private void getData() {
        Map<String, Object> map = new HashMap<>();
        OkHttpUtil.postJson(getActivity(), Constant.URL.refresh_token, null, map, this);
        isShowShop();
    }

    /**
     * 升级Vip填写邀请码
     *
     * @param Code
     */
    @Override
    public void finishInvitateCode(String Code) {
        shengjivipSucc(Code);
        /*loadingDialog = LoadingDialog.newInstance("请求中...");
        loadingDialog.show(getActivity().getFragmentManager());
        Map<String, Object> map = new HashMap<>();
        OkHttpUtil.postJson(getActivity(), Constant.URL.member_upgrade, new MemberUpgrade(Code), map, this);
    */
    }


    /**
     * 升级Vip邀请函对话框
     *
     * @param invateCode
     * @param isInput
     */
    @Override
    public void finishInvitateCard(String invateCode, boolean isInput) {
        if (isInput) {//已输入邀请码点确认
        /*    if (bindMobileDialog == null)
                bindMobileDialog = BindMobileDialog.newInstance(getActivity());
            bindMobileDialog.setListener(this);
            bindMobileDialog.show(getActivity().getFragmentManager());*/
        } else {//选择我没有邀请码
            startActivity(new Intent(getActivity(), UpgradeVipActivity.class));
        }
    }

    @Override
    public void onResponse(String url, String json) {
        LogUtil.jLog().e(json);
        if (!TextUtils.isEmpty(json)) {
            if (Constant.URL.refresh_token.equals(url)) { //刷新Token
                LogeUtil.e("refresh_token", json);
                dismissLoading();
                refreshtoken = gson.fromJson(json, RefreshtokenEntity.class);
                if (Constant.Strings.SUC.equals(refreshtoken.getCode())) {
                    //改变 主页bottom vip 图标及文字颜色
                    mRxManager.post(getResources().getString(R.string.ChangeMainBotton_vip_dirwableAndColor), refreshtoken.getBody().getMember().getType());

                    SharedPreferencesUtil.saveRoleInfo(getActivity(), json);
                    SharedPreferencesUtil.saveToken(getContext(), refreshtoken.getBody().getToken());
                    UpdateUI(refreshtoken.getBody().getMember(), refreshtoken.getBody());
                    if (isUpgradeVip && SharedPreferencesUtil.getWechatStatus(getActivity())) {
                        SharedPreferencesUtil.saveWechatStatus(getActivity(), false);
                        if (TextUtils.isEmpty(refreshtoken.getBody().getMember().getMobile())) {
                            isUpgradeVip = false;
                            bindMobileDialog = BindMobileDialog.newInstance(getContext(), false);
                            bindMobileDialog.setListener(this);
                            bindMobileDialog.show(getActivity().getFragmentManager());
                        } else {
                            UpgradeSvipDialog dialog = UpgradeSvipDialog.newInstance(getContext(), "您已升级VIP", "");
                            dialog.setOnItemClickListener(this);
                            dialog.show(getActivity().getFragmentManager());
                        }
                    }

                    if (refreshtoken.getBody().getMember().getParent() == null) {
                        tvVipRecommer.setVisibility(View.GONE);
                    } else {
                        tvVipRecommer.setVisibility(View.VISIBLE);
                    }
                } else {
                    isUpgradeVip = false;
                    ToastUtil.initToast(getContext(), refreshtoken.getMsg());
                }
            } else if (Constant.URL.member_upgrade.equals(url)) {  //会员升级
                dismissLoading();
                LogeUtil.e("member_upgrade", json);
                MemberUpgradeEntity swe = gson.fromJson(json, MemberUpgradeEntity.class);
                if (Constant.Strings.SUC.equals(swe.getCode())) {
                    SharedPreferencesUtil.saveWechatPayType(getActivity(), "1");

                    getData();
                    UpgradeSvipDialog dialog = UpgradeSvipDialog.newInstance(getContext(), swe.getBody().getTips(), swe.getBody().getAttachTips());
                    dialog.setOnItemClickListener(this);
                    dialog.show(getActivity().getFragmentManager());
                } else {
                    ToastUtil.initToast(getContext(), swe.getMsg());
                }
            } else if (Constant.URL.members.equals(url)) { //绑定手机号

                dismissLoading();
                LogeUtil.e("members", json);
                SmsEntity se = gson.fromJson(json, SmsEntity.class);
                if (Constant.Strings.SUC.equals(se.getCode())) {
                    if (bindMobileDialog != null) {
                        bindMobileDialog.dismiss();
                    }
                    ToastUtil.initToast(getContext(), "绑定成功");
                    getData();
                    if (isUpgradeVip) {
                        isUpgradeVip = false;
                        UpgradeSvipDialog dialog = UpgradeSvipDialog.newInstance(getContext(), "您已升级VIP", "");
                        dialog.setOnItemClickListener(this);
                        dialog.show(getActivity().getFragmentManager());
                    }
                } else {
                    ToastUtil.initToast(getContext(), se.getMsg());
                }
            } else if (Constant.URL.member_profits.equals(url)) { //收益统计
                LogeUtil.e("member_profits", json);
                memberProfitsEntity mp = gson.fromJson(json, memberProfitsEntity.class);
                mp2 = gson.fromJson(json, memberProfitsEntity.class);
                if (Constant.Strings.SUC.equals(mp.getCode())) {

                    UpdateData(mp.getBody(), mp.getBody().getDayProfit(), mp.getBody().getTotalProfit());
                    tv_head_des.setText(mp2.getBody().getInvitedDescription());

                } else {
                    ToastUtil.initToast(getActivity(), mp.getMsg());
                }
            } else if (Constant.URL.vips_invite_buttons.equals(url)) { //邀请按钮文案
                LogeUtil.e("vips_invite_buttons", json);
                Vips_invite_buttonsEntity mp = gson.fromJson(json, Vips_invite_buttonsEntity.class);
                if (Constant.Strings.SUC.equals(mp.getCode())) {
                    tv_vipSubTitle1.setText(mp.getBody().getDownload().getSubTitle());
                    tv_vipTitle1.setText(mp.getBody().getDownload().getTitle());
                    tv_vipSubTitle.setText(mp.getBody().getFriend().getSubTitle());
                    tv_vipTitle.setText(mp.getBody().getFriend().getTitle());

                    tv_svipSubTitle1.setText(mp.getBody().getDownload().getSubTitle());
                    tv_svipTitle1.setText(mp.getBody().getDownload().getTitle());
                    tv_svipSubTitle.setText(mp.getBody().getFriend().getSubTitle());
                    tv_svipTitle.setText(mp.getBody().getFriend().getTitle());
                } else {
                    ToastUtil.initToast(getActivity(), mp.getMsg());
                }
            } else if (Constant.URL.modules_member_configurations.equals(url)) { //头部按钮文案及 轮播图
                isClickYXZQneedReflash = false;
                LogeUtil.e("modules_member_configurations", json);
                MemberConfigurations mp = gson.fromJson(json, MemberConfigurations.class);
                if (Constant.Strings.SUC.equals(mp.getCode())) {
                    if (mp.getBody() != null && mp.getBody().getTasks() != null) {
                        yaoXinHeadAdapter.setData(mp.getBody().getTasks());
                        if (mp.getBody().getTasks().size() == 0) {
                            view_head.setVisibility(View.GONE);
                        } else {
                            view_head.setVisibility(View.VISIBLE);

                        }

                    }
                    initConfig(mp);
                } else {
                    ToastUtil.initToast(getActivity(), mp.getMsg());
                }
            } else if (Constant.URL.material_recommend.equals(url)) {//邀新专区
                //  statusLayoutManager.showSuccessLayout();
                LogeUtil.e("material_recommend", json);
                MaterialRecommendEntity materialRecommendEntity = gson.fromJson(json, MaterialRecommendEntity.class);
                removeLoadingItem();
                if (pageNo == 1) {
                    data.clear();
                }
                dismissLoading();
                if ("200".equals(materialRecommendEntity.getCode())) {
                    if (materialRecommendEntity.getBody().getDataList() != null) {
                        boolean isTranslucentStatus = false;

                        data.addAll(materialRecommendEntity.getBody().getDataList());


                        // 一般来讲， ImageWatcher 需要占据全屏的位置
// 如果是透明状态栏，你需要给ImageWatcher标记 一个偏移值，以修正点击ImageView查看的启动动画的Y轴起点的不正确
// 配置error图标 如果不介意使用lib自带的图标，并不一定要调用这个API
//设置指示器（默认小白点）
//设置指示器颜色
// 长按图片的回调，你可以显示一个框继续提供一些复制，发送等功能
//调用show方法前，请先调用setLoader 给ImageWatcher提供加载图片的实现
                        vImageWatcher = ImageWatcher.Helper.with(getActivity()) // 一般来讲， ImageWatcher 需要占据全屏的位置
                                .setTranslucentStatus(!isTranslucentStatus ? Utils.calcStatusBarHeight(getContext()) : 0) // 如果是透明状态栏，你需要给ImageWatcher标记 一个偏移值，以修正点击ImageView查看的启动动画的Y轴起点的不正确
                                .setErrorImageRes(R.mipmap.error_picture) // 配置error图标 如果不介意使用lib自带的图标，并不一定要调用这个API
                                .setHintMode(ImageWatcher.POINT)//设置指示器（默认小白点）
                                .setHintColor(getResources().getColor(R.color.colorRed), getResources().getColor(R.color.colorWhite))//设置指示器颜色
                                .setOnPictureLongPressListener(this) // 长按图片的回调，你可以显示一个框继续提供一些复制，发送等功能
                                .setLoader(new ImageWatcher.Loader() {//调用show方法前，请先调用setLoader 给ImageWatcher提供加载图片的实现
                                    @Override
                                    public void load(Context context, String url, final ImageWatcher.LoadCallback lc) {
                                        Glide.with(context).asBitmap().load(url).into(new SimpleTarget<Bitmap>() {
                                            @Override
                                            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                                                lc.onResourceReady(resource);
                                            }

                                            @Override
                                            public void onLoadStarted(Drawable placeholder) {
                                                lc.onLoadStarted(placeholder);
                                            }

                                            @Override
                                            public void onLoadFailed(Drawable errorDrawable) {
                                                lc.onLoadFailed(errorDrawable);
                                            }
                                        });
                                    }
                                })
                                .create();


                        if (materialRecommendEntity.getBody().isHasNext()) {
                            data.add(new MaterialRecommendEntity.BodyEntity.DataListEntity(1));
                            nextIndex = pageNo + 1;

                        } else {
                            addBaseLine();
                        }
                    } else {
                        addBaseLine();
                    }


                }
                dynamicListAdapter.setData(data);


            } else if ((Constant.URL.adverts + "173000").equals(url)) {
                LogeUtil.e("adverts" + "173000", json);
                AEntity = gson.fromJson(json, advertsCodeEntity.class);
                if ("200".equals(AEntity.getCode())) {
                    //保存当前时间+有效时间
                    SharedPreferencesUtil.saveLastInvitFriendTime(getActivity(), (System.currentTimeMillis() + AEntity.getBody().get(0).getPeriodTime() * 1000) + "");
                    //弹出邀请好友框
                    invitedFriendDialog = InvitedFriendDialog.newInstance(getActivity(), AEntity.getBody().get(0).getMaterial().getUrl());
                    invitedFriendDialog.setOnItemClickListener(new BaseDialog.OnItemClickListener() {
                        @Override
                        public void onItemClick(View v) {
//                            startActivity(new Intent(getActivity(), InviteFriendActivity.class));
/*                            if ("1".equals(refreshtoken.getBody().getMember().getType())) {
                                startActivity(new Intent(getContext(), InviteLiBaoActivity.class));
                            } else if ("2".equals(refreshtoken.getBody().getMember().getType())) {
                                Intent intent = new Intent(getActivity(), SVIPLibaoAndFreeActivity.class);
                                intent.putExtra("type", 0);
                                startActivity(intent);
                            }*/
                            if (AEntity.getBody().get(0).getJumpType() == 1) {//jumpType": "integer,跳转类型，1 APP页面跳转，
                                if (AEntity.getBody().get(0).getUrl().contains("page/house/detail?id=")) {//id为房源ID，如有其它参数原样带入查询
                                    String[] split = AEntity.getBody().get(0).getUrl().split("=");

                                    Intent intent1 = new Intent(getContext(), HouseDetailsActivityFor3.class);
                                    intent1.putExtra("houseId", split[1]);
                                    intent1.putExtra("persellId", split[1]);
//                    intent.putExtra("type", data.get(position).getType());
                                    startActivity(intent1);
                                } else if (AEntity.getBody().get(0).getUrl().contains("page/village/detail?id=")) {//id为目的地ID，如有其它参数原样带入查询
//"page/village/detail";  目的地详情页

                                    String[] split = AEntity.getBody().get(0).getUrl().split("=");

                                    Intent intent1 = new Intent(getContext(), BourbonListActivity.class);

                                    intent1.putExtra("villageId", split[1]);
                                    intent1.putExtra("city", "");
                                    intent1.putExtra("area", "");
                                    startActivity(intent1);
                                } else if (AEntity.getBody().get(0).getUrl().contains("page/presell/detail?id=")) {//id为预售ID，如有其它参数原样带入查询
                                    String[] split = AEntity.getBody().get(0).getUrl().split("=");

                                    Intent intent1 = new Intent(getContext(), HouseDetailsActivityFor3.class);
                                    intent1.putExtra("houseId", split[1]);
                                    intent1.putExtra("persellId", split[1]);
                                    intent1.putExtra("presellProduct", true);
//              intent.putExtra("type", data.get(position).getType());
                                    startActivity(intent1);
                                } else if (AEntity.getBody().get(0).getUrl().contains("page/village/list")) {//找房源-别墅
                                    // jumps.orderJump(1, 0);
                                    Intent intent = new Intent(getContext(), JDMSBSActivity.class);
                                    intent.putExtra("type", 0);

                                    getContext().startActivity(intent);

                                } else if (AEntity.getBody().get(0).getUrl().contains("page/house/list")) {//找房源-民宿
                                   /* if (jumps != null) {
                                        jumps.orderJump(1, 1);
                                    }*/
                                    Intent intent = new Intent(getContext(), JDMSBSActivity.class);
                                    intent.putExtra("type", 0);

                                    getContext().startActivity(intent);
                                } else if (AEntity.getBody().get(0).getUrl().contains("page/member")) {//我的

                                    if (jumps != null) {
                                        jumps.orderJump(4, -1);
                                    }

                                } else if (AEntity.getBody().get(0).getUrl().contains("page/presell/search")) {//预售搜索
                                    startActivity(new Intent(getContext(), Home_temaiSearchActivity.class));

                                } else if (AEntity.getBody().get(0).getUrl().contains("page/home")) {//首页
                                    if (VPListener != null) {
                                        VPListener.vipJump();
                                    }

                                } else if ("page/search".equals(AEntity.getBody().get(0).getUrl())) {
                                    //"page/search";  房源搜索索引页

                                    Intent intent1 = new Intent(getContext(), SearchBournActivity.class);
                                    intent1.putExtra("cityId", AppContext.currentCityidCurrent);
                                    startActivity(intent1);
                                } else if ("page/search/result".equals(AEntity.getBody().get(0).getUrl())) { //"page/search/result";  房源搜索结果页
                                    Intent intent = new Intent(getContext(), BieShuSearchResultActivity.class);
                                    intent.putExtra("isBieShu", true);
                                } else if ("page/member/order".equals(AEntity.getBody().get(0).getUrl())) {
                                    //"page/member/order";  我的订单
                                    Intent intent1 = new Intent(getContext(), MyOrderActivity.class);
                                    startActivity(intent1);
                                } else if ("page/vip".equals(AEntity.getBody().get(0).getUrl())) {
                                    //"page/vip";  VIP

                                } else if ("page/vip/share".equals(AEntity.getBody().get(0).getUrl())) {
                                    //"page/vip/share";  vip邀请好友分享页
                                    if ("1".equals(SharedPreferencesUtil.getUserInfo(getContext()).getBody().getMember().getType())) {//vip
                                        startActivity(new Intent(getContext(), InviteLiBaoActivity.class));

                                    } else if ("2".equals(SharedPreferencesUtil.getUserInfo(getContext()).getBody().getMember().getType())) {//svip
                                        startActivity(new Intent(getContext(), SVIPFreeActivity.class));

                                    }
                                } else if ("page/vip/draw".equals(AEntity.getBody().get(0).getUrl())) {
                                    //"page/vip/draw";  vip提款页
                                    startActivity(new Intent(getContext(), CashWithdrawalActivity.class));

                                } else if ("page/search?type=1".equals(AEntity.getBody().get(0).getUrl())) {//民宿搜索页
                                    Intent intent = new Intent(getContext(), SearchMinSu2VActivity.class);
                                    startActivity(intent);
                                } else if ("page/search/result?type=1".equals(AEntity.getBody().get(0).getUrl())) {//民宿搜索结果页
                                    Intent intent = new Intent(getContext(), MinsuSearchResultActivity.class);
                                    intent.putExtra("businessDistrictId", matchUrl(AEntity.getBody().get(0).getUrl(), "businessDistrictId"));
                                    intent.putExtra("tag", matchUrl(AEntity.getBody().get(0).getUrl(), "tag"));
                                    startActivity(intent);

                                } else if ("page/vip/download".equals(AEntity.getBody().get(0).getUrl())) {//VIP邀请下载页
                                    Intent intent = new Intent(getContext(), InviteDownloadActivity.class);
                                    startActivity(intent);
                                }
                            } else if (AEntity.getBody().get(0).getJumpType() == 2 && !TextUtils.isEmpty(AEntity.getBody().get(0).getUrl())) {//2 内嵌页面链接跳转，
                                Intent intent = new Intent(getContext(), H5AutoTitleActivity.class);
                                intent.putExtra("title", "爱订房");
                                intent.putExtra("url", AEntity.getBody().get(0).getUrl());
                                startActivity(intent);
                            } else if (AEntity.getBody().get(0).getJumpType() == 3) {//3  跳转小程序",
                                wxOpenApplet(AEntity.getBody().get(0).getMiniAppId(), AEntity.getBody().get(0).getUrl(), AEntity.getBody().get(0).getMiniProgramType());
                            }
                            isneewReflash = true;
                        }
                    });
                    invitedFriendDialog.show(getActivity().getFragmentManager());

                }
            } else if (Constant.URL.global_configurations.equals(url)) {//我的收益说明
                dismissLoading();
                LogeUtil.e("global_configurations", json);
                Global_configurations global_configurations = gson.fromJson(json, Global_configurations.class);
                if ("200".equals(global_configurations.getCode())) {
/*                    CustomPopupWindow.Builder builder = new CustomPopupWindow.Builder();
                    final CustomPopupWindow builder1 = builder.setheight(LinearLayoutCompat.LayoutParams.MATCH_PARENT)
                            .setwidth(LinearLayoutCompat.LayoutParams.MATCH_PARENT)
                            .setOutSideCancel(true)
                            .setContext(getContext())
                            .isBlur(true)
                            .setRadius(5)
                            .setActivity(getActivity())
                            .setContentView(R.layout.popu_vip_chakanshouyi2)
                            .setOnDismissListener(new PopupWindow.OnDismissListener() {
                                @Override
                                public void onDismiss() {
                                }
                            })
                            .builder();

                    builder1.showAsLaction(view, Gravity.BOTTOM, 0, 0);
                    builder1.getItemView(R.id.tv_know).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            builder1.dismiss();
                        }
                    });
                    builder1.getItemView(R.id.close).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            builder1.dismiss();
                        }
                    });
                    RecyclerView itemrv = (RecyclerView) builder1.getItemView(R.id.rv);
                    itemrv.setLayoutManager(new LinearLayoutManager(getContext()));
                    PopuShouYiChaKanAdapter popuShouYiChaKanAdapter = new PopuShouYiChaKanAdapter(getContext());
                    itemrv.setAdapter(popuShouYiChaKanAdapter);
                    popuShouYiChaKanAdapter.setData(global_configurations.getBody().getIncomeDescriptions());*/
                    IncomeIntroduceDialog dialog = IncomeIntroduceDialog.newInstance(gson.toJson(global_configurations.getBody()));
                    dialog.show(getActivity().getFragmentManager());
                }


            } else if (Constant.URL.merchant_share.equals(url)) {//我的店铺
                LogeUtil.e("merchant_share", json);

                merchant_shareEntity = gson.fromJson(json, Merchant_shareEntity.class);
                if ("200".equals(merchant_shareEntity.getCode()) && merchant_shareEntity.getBody().getShowMerchant() == 1) {
                    //"showMerchant": "integer,是否展示入口按钮,1:展示 0:不展示",
                    tv_svip_myShop.setVisibility(View.VISIBLE);
                    tv_vip_myStore.setVisibility(View.VISIBLE);

                } else {
                    tv_svip_myShop.setVisibility(View.GONE);
                    tv_vip_myStore.setVisibility(View.GONE);

                }


            }

        }
    }

    private void shengjivipSucc(String code) {
        SharedPreferencesUtil.saveWechatPayType(getActivity(), "1");

        getData();
        if ("1".equals(code)) {
            UpgradeSvipDialog dialog = UpgradeSvipDialog.newInstance(getContext(), "您已免费升级VIP", "(价值¥299/年)");
            dialog.setOnItemClickListener(this);
            dialog.show(getActivity().getFragmentManager());
        } else {
            UpgradeSvipDialog dialog = UpgradeSvipDialog.newInstance(getContext(), "您已免费升级SVIP", "(价值¥299/年)");
            dialog.setOnItemClickListener(this);
            dialog.show(getActivity().getFragmentManager());
        }

    }

    private void removeLoadingItem() {
        if (data.size() > 0) {
            if (data.get(data.size() - 1).getMyType() == 1) {
                data.remove(data.size() - 1);
            }
        }
    }

    private void addBaseLine() {
        if (pageNo != 1) {
            data.add(new MaterialRecommendEntity.BodyEntity.DataListEntity(2));
        }
    }

    //三期初始化 头部及广告页
    private void initConfig(MemberConfigurations mc) {
        final MemberConfigurations.BodyBean body = mc.getBody();
        if (body.getHeaderAdverts() != null && body.getHeaderAdverts().size() > 0) {
//头部广告位
            headerAdverts = body.getHeaderAdverts();
            ll_top.setVisibility(View.VISIBLE);
            tv_vip_top.setText(body.getHeaderAdverts().get(0).getMaterial().getText());
            //头部提现
            tv_vip_tixian.setText(body.getHeaderAdverts().get(0).getMaterial().getBtnName());
        } else {
            ll_top.setVisibility(View.GONE);

        }
        //中间广告位
        if (body.getMiddleAdverts() != null && body.getMiddleAdverts().size() > 0) {
            viewPager.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                    (int) (PhoneUtil.getPhoneWidth(getContext()) / 5.4)));

            nsv.setLayoutParams(new AppBarLayout.LayoutParams(AppBarLayout.LayoutParams.MATCH_PARENT,
                    (int) (PhoneUtil.getPhoneWidth(getContext()) / 5.4)));


            vipMidAdvAdapter = new VipMidAdvAdapter(jumps, VPListener);
            viewPager.setAdapter(vipMidAdvAdapter);
            viewPager.setSlideBorderMode(AutoScrollViewPager.SLIDE_BORDER_MODE_CYCLE);
            viewPager.setInterval(2300);
            viewPager.setAutoScrollDurationFactor(4);
            viewPager.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()) {
                        case MotionEvent.ACTION_MOVE:
                            break;
                        case MotionEvent.ACTION_UP:
                        case MotionEvent.ACTION_CANCEL:
                            break;
                    }
                    return false;
                }
            });

            viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {

                    if (navView == null) {
                        return;
                    }
                    if (position == 0) {
                        navView.setCurrentItem(body.getMiddleAdverts().size() - 1);
                    } else if (position == body.getMiddleAdverts().size() + 1) {
                        navView.setCurrentItem(0);
                    } else {
                        navView.setCurrentItem(position - 1);
                    }
                }

                @Override
                public void onPageScrollStateChanged(int state) {
                    if (viewPager == null) {
                        return;
                    }
                    if (state == 0) {
                        if (viewPager.getCurrentItem() == body.getMiddleAdverts().size() + 1) {
                            viewPager.setCurrentItem(1, false);
                        } else if (viewPager.getCurrentItem() == 0) {
                            viewPager.setCurrentItem(body.getMiddleAdverts().size(), false);
                        }
                    }

                }
            });
            vipMidAdvAdapter.setData(body.getMiddleAdverts());
        }


    }

    private String matchUrl(String url, String parm) {
        if (url.contains("?")) {
            String parentValue = url.split("\\?")[1];
            if (parentValue.contains(parm)) {
                if (parentValue.contains("&")) {
                    String[] childValue = parentValue.split("&");
                    for (int i = 0; i < childValue.length; i++) {
                        if (childValue[i].contains(parm)) {
                            return childValue[i].split("=")[1];
                        }
                    }
                } else {
                    return parentValue.split("=")[1];
                }
            } else {
                return "";
            }
        } else {
            return "";
        }
        return "";
    }


    @Override
    public void onFailure(String url, String error) {

    }

    private Jumps jumps;

    @Override
    public void onPictureLongPress(ImageView v, String url, int pos) {

    }

    @Override
    public void onCallback() {
        if (nextIndex == pageNo + 1) {
            pageNo++;
            getDataSuCai();
        }
    }

    @Override
    public void onThumbPictureClick(ImageView i, List<ImageView> imageGroupList, List<String> urlList) {
        vImageWatcher.show(i, imageGroupList, urlList);

    }

    @Override
    public void onThumbPictureClick(int positopn, ImageView i, List<ImageView> imageGroupList, List<String> urlList) {
        vImageWatcher.show1(positopn, i, imageGroupList, urlList);

    }

    public interface Jumps {
        void orderJump(int jumpType, int innerJumpType);
    }

    public void setJumps(Jumps jumps) {
        this.jumps = jumps;
    }


    private void UpdateData(memberProfitsEntity.BodyBean bodybean, memberProfitsEntity.BodyBean.DayProfitBean dayBean, memberProfitsEntity.BodyBean.TotalProfitBean totalBean) {

        String Totalincome = totalBean.getAmountsValue(); //累计收益
        String Currentbalance = bodybean.getBalanceValue(); //账户总余额
        String Unfrozen = bodybean.getUnfrozenValue();//可提现余额
        String todayIncome = dayBean.getAmountsValue();//今日收益
        String canWithdral = bodybean.getUnfrozenValue();//可提现数

        String directIncome = bodybean.getDirectProfit().getAmountsValue();
        String fissionIncome = bodybean.getFissionProfit().getAmountsValue();

        tvSvipTotalIncome.setText("¥" + Totalincome);//svip累计收益
        tvSvipCureentBalance.setText("¥" + directIncome); // svip直接收益
        tvSvipTodayIncome.setText("¥" + fissionIncome);// svip裂变红包
        tvSvipBalance.setText("¥" + Currentbalance);
        tvSvipCanWithdrawl.setText("(" + Unfrozen + "可提现)");//svip可提现余额
        tvSvipClient.setText(totalBean.getNormalFans() + ""); //svip客户
        tvSvipLowerLevel.setText(totalBean.getVipFans() + ""); //svip我的下级

        tvVipTotalIncome.setText("¥" + Totalincome);//vip累计收益
//        tvVipCureentBalance.setText("¥" + PhoneUtil.handleDecimal2((Currentbalance / 100.0) + "")); // vip当前余额
//        tvVipTodayIncome.setText("¥" + PhoneUtil.handleDecimal2((todayIncome / 100.0) + ""));// vip今日收益
        tvVipCureentBalance.setText("¥" + directIncome); // vip当前余额
        tvVipTodayIncome.setText("¥" + fissionIncome);// vip今日收益
        //总金额
        tvVipBalance.setText("¥" + Currentbalance);
        tvVipCanWithdrawl.setText("(" + Unfrozen + "可提现)");//Vip可提现余额
        tvVipClient.setText(totalBean.getNormalFans() + ""); //vip客户
        totalIncmome = Totalincome;
        tvVipLowerLevel.setText(totalBean.getVipFans() + ""); //svip我的下级

        if (bodybean.isAllowFission()) {
            tvFissionRedEnvelope.setVisibility(View.VISIBLE);
        } else {
            tvFissionRedEnvelope.setVisibility(View.GONE);
        }

        tvFissionRedEnvelope.setText(bodybean.getFissionPercent() + "%");

        //vip字体设置
        PhoneUtil.setExternalFont(getActivity(), tvVipTotalIncome, true);
        PhoneUtil.setExternalFont(getActivity(), tvVipCureentBalance, true);
        PhoneUtil.setExternalFont(getActivity(), tvVipTodayIncome, true);

        PhoneUtil.setExternalFont(getActivity(), tvVipBalance, true);
        PhoneUtil.setExternalFont(getActivity(), tvVipClient, true);
//        PhoneUtil.setExternalFont(getActivity(), tvVipCanWithdrawl, true);//Vip可提现余额

        //svip字体设置
        PhoneUtil.setExternalFont(getActivity(), tvSvipTotalIncome, true);
        PhoneUtil.setExternalFont(getActivity(), tvSvipCureentBalance, true);
        PhoneUtil.setExternalFont(getActivity(), tvSvipTodayIncome, true);

        PhoneUtil.setExternalFont(getActivity(), tvSvipBalance, true);
//        PhoneUtil.setExternalFont(getActivity(), tvSvipCanWithdrawl, true);
        PhoneUtil.setExternalFont(getActivity(), tvSvipClient, true);
        PhoneUtil.setExternalFont(getActivity(), tvSvipLowerLevel, true);
        tvSvipCanWithdrawl.setText("" + Unfrozen);//svip可提现余额
        tvSvipClient.setText(totalBean.getNormalFans() + ""); //svip客户
        tvSvipLowerLevel.setText(totalBean.getVipFans() + ""); //svip我的下级
        //三期


        if ("1".equals(refreshtoken.getBody().getMember().getType())) {//
            ll_vip_svip.setVisibility(View.GONE);

        } else if ("2".equals(refreshtoken.getBody().getMember().getType())) {//svip
            //SVIP
            ll_vip_svip.setVisibility(View.VISIBLE);

            tv_vip_svip.setText(totalBean.getSvipFans() + "");
        }

        if ("1".equals(refreshtoken.getBody().getMember().getType())) {//
            tv_vip_fenyongshezhi.setVisibility(View.GONE);
            view_fenyongshezhi.setVisibility(View.GONE);

        } else if ("2".equals(refreshtoken.getBody().getMember().getType())) {//svip
            //SVIP
            tv_vip_fenyongshezhi.setVisibility(View.VISIBLE);
            view_fenyongshezhi.setVisibility(View.VISIBLE);

        }
        if ("1".equals(refreshtoken.getBody().getMember().getType())) {//
            tv_vip_myStore.setVisibility(View.GONE);
            ll_vip_des.setVisibility(View.VISIBLE);
            tv_vip_des.setText(bodybean.getUpgradeDescription());
            img.setImageResource(R.drawable.member_invite_bg_vip);
            ll_yaoxin_head.setBackgroundResource(R.drawable.vip_shape);


        } else if ("2".equals(refreshtoken.getBody().getMember().getType())) {//svip
            //SVIP
            //tv_vip_myStore.setVisibility(View.VISIBLE);
            ll_vip_des.setVisibility(View.GONE);
            img.setImageResource(R.drawable.member_invite_bg_svip);
            ll_yaoxin_head.setBackgroundResource(R.drawable.svip_shape);

        }

        if (bodybean.getAddBrokerageActivityStatus() == 1) {//加返佣金
            tv_vip_tixian1.setVisibility(View.VISIBLE);
        } else {
            tv_vip_tixian1.setVisibility(View.INVISIBLE);

        }


        //VIP
        tv_vip_vip.setText(totalBean.getVipFans() + "");

        //粉丝
        tv_vip_fans.setText(totalBean.getNormalFans() + "");
        if (TextUtils.isEmpty(bodybean.getUnfrozenAddBrokerageAmountValue()) || "0".equals(bodybean.getUnfrozenAddBrokerageAmountValue())) {
            ll_vip_yongjin.setVisibility(View.GONE);
        } else {
            ll_vip_yongjin.setVisibility(View.VISIBLE);

        }
        /*if (TextUtils.isEmpty(bodybean.getUnfrozenAddBrokerageAmountValue())||Double.parseDouble(bodybean.getUnfrozenAddBrokerageAmountValue())==0){

        }*/

        //加返佣金
        tv_vip_yongjin.setText(bodybean.getUnfrozenAddBrokerageAmountValue());
        //立即邀请文案
        tv_invent_des.setText(bodybean.getInvitedDescription());

        //余额
        tv_vip_balance.setText("" + bodybean.getBalanceValue());

        //累计收入
        tv_vip_leiji.setText("" + totalBean.getAmountsValue());

        /*//裂变红包
        tv_vip_liebian.setText("" + bodybean.getFissionProfit().getAmountsValue());

        //可提金额
        tv_vip_ketixiannum.setText("" + Unfrozen);


        //团队管理
        tv_vip_tuanduinum.setText(bodybean.getTotalProfit().getGroupFans() + "");*/


    }

    /**
     * 刷新UI界面
     *
     * @param d
     */
    private void UpdateUI(RefreshtokenEntity.BodyBean.MemberBean d, RefreshtokenEntity.BodyBean b) {

        switch (d.getType()) {
            case "0": {
                swipeRefreshLayout.setVisibility(View.VISIBLE);
                rlOrdinaryVip.setVisibility(View.VISIBLE);
                rl_vip.setVisibility(View.VISIBLE);

                rlVip.setVisibility(View.GONE);
                rlSVip.setVisibility(View.GONE);
                tvNickName.setText(d.getNickName());
                sdvHead.setImageURI(PhoneUtil.getHead(d.getHeaderUrl()));
                getVip();
                break;
            }
            case "1": {
//三期
                swipeRefreshLayout.setVisibility(View.GONE);
                include.setVisibility(View.VISIBLE);
                rl_vip.setVisibility(View.GONE);

                ll_bg1.setBackgroundResource(R.drawable.top_bg_vip_3);
                //头像
                sdv_vip_head.setImageURI(PhoneUtil.getHead(d.getHeaderUrl()));

                //角色类别
                img_vip_type.setImageResource(R.drawable.tag_vip_3);

                //名字
                tv_vip_name.setText(d.getNickName());

                //邀请码
                tv_vip_inventCode.setText("邀请码：" + d.getInviteCode());

                rv_comments.setLayoutManager(new LinearLayoutManager(getContext()));
                rv_comments.addItemDecoration(new RVItemDecoration(LinearLayout.VERTICAL, PhoneUtil.dp2px(getContext(), 1), getResources().getColor(R.color.colorBgEEE), PhoneUtil.dp2px(getContext(), 1)));
                dynamicListAdapter = new VipDynamicListAdapter(getContext(), this, this, this);


                inflate = View.inflate(getContext(), R.layout.head_vip, null);
                dynamicListAdapter.addHeaderView(inflate);
                initHead(inflate);
                dynamicListAdapter.setPictureClickCallback(this);

                rv_comments.setAdapter(dynamicListAdapter);

                //邀新专区头部
                rv_yaoxin_head.setLayoutManager(new LinearLayoutManager(getContext()));
                if (rv_yaoxin_head.getItemDecorationCount() == 0) {//防止重复添加装饰线
                    rv_yaoxin_head.addItemDecoration(new RVItemDecoration(LinearLayout.VERTICAL, PhoneUtil.dp2px(getContext(), 1), getResources().getColor(R.color.colorBgEEE), PhoneUtil.dp2px(getContext(), 1)));
                }
                yaoXinHeadAdapter = new YaoXinHeadAdapter(getContext(), jumps, VPListener, OrdinaryVipFragment.this);
                rv_yaoxin_head.setAdapter(yaoXinHeadAdapter);


                rlOrdinaryVip.setVisibility(View.GONE);
                rlVip.setVisibility(View.VISIBLE);
                rlSVip.setVisibility(View.GONE);
                sdvvipHead.setImageURI(PhoneUtil.getHead(d.getHeaderUrl()));
                tvvipNickName.setText(d.getNickName());
                Map<String, String> map = new HashMap<>();
                tvVipOffectiveDate.setVisibility(View.INVISIBLE);
                tvVipOffectiveDate.setText("有效期至" + d.getExpireTime());
                tv_head_des.setTextColor(Color.parseColor("#72727D"));

                OkHttpUtil.getJSON(getContext(), Constant.URL.member_profits, map, this);
                OkHttpUtil.getJSON(getContext(), Constant.URL.vips_invite_buttons, map, this);


                tvCopyAddressVip.setText(d.getInviteCode());//vip下级会员
                if (TextUtils.isEmpty(d.getInviteCode())) {
                    llInviteateCodeVip.setVisibility(View.GONE);
                }

                //GET 开发完成 /modules/member/configurations 会员中心配置
                OkHttpUtil.getJSON(getContext(), Constant.URL.modules_member_configurations, map, this);
                //GET 开发中 /material/recommend/list 推荐素材列表
                pageNo = 1;
                nextIndex = 1;
                getDataSuCai();
                InviteFriend();

                tv_vip_tixian2.setTextColor(Color.parseColor("#72727D"));
                tv_vip_tixian2.setBackground(getResources().getDrawable(R.drawable.tixian1));


                Drawable drawable = getResources().getDrawable(R.drawable.member_arrow_detail);
/// 这一步必须要做,否则不会显示.
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                tv_vip_tixian2.setCompoundDrawables(null, null, drawable, null);
                if (b != null && b.getMerchant() != null && b.getMerchant().isShowSupplier()) {//供应商管理
                    ll_gysgl.setVisibility(View.VISIBLE);
                } else {
                    ll_gysgl.setVisibility(View.GONE);

                }
                break;
            }
            case "2": {

                //三期
                swipeRefreshLayout.setVisibility(View.GONE);
                include.setVisibility(View.VISIBLE);
                rl_vip.setVisibility(View.GONE);

                ll_bg1.setBackgroundResource(R.drawable.top_bg_svip_3);

                //头像
                sdv_vip_head.setImageURI(PhoneUtil.getHead(d.getHeaderUrl()));
                //角色类别
                if ("0".equals(d.getLevel())){
                    img_vip_type.setImageResource(R.drawable.member_tag_svip);

                }else {
                    img_vip_type.setImageResource(R.drawable.tag_svip_hhr);

                }


                //名字
                tv_vip_name.setText(d.getNickName());

                //邀请码
                tv_vip_inventCode.setText("邀请码：" + d.getInviteCode());
                rv_comments.setLayoutManager(new LinearLayoutManager(getContext()));
                rv_comments.addItemDecoration(new RVItemDecoration(LinearLayout.VERTICAL, PhoneUtil.dp2px(getContext(), 1), getResources().getColor(R.color.colorBgEEE), PhoneUtil.dp2px(getContext(), 1)));
                dynamicListAdapter = new VipDynamicListAdapter(getContext(), this, this, this);
                inflate = View.inflate(getContext(), R.layout.head_vip, null);
                dynamicListAdapter.addHeaderView(inflate);
                initHead(inflate);
                dynamicListAdapter.setPictureClickCallback(this);
                rv_comments.setAdapter(dynamicListAdapter);
                //邀新专区头部
                rv_yaoxin_head.setLayoutManager(new LinearLayoutManager(getContext()));
                if (rv_yaoxin_head.getItemDecorationCount() == 0) {//防止重复添加装饰线
                    rv_yaoxin_head.addItemDecoration(new RVItemDecoration(LinearLayout.VERTICAL, PhoneUtil.dp2px(getContext(), 1), getResources().getColor(R.color.colorBgEEE), PhoneUtil.dp2px(getContext(), 1)));
                }                yaoXinHeadAdapter = new YaoXinHeadAdapter(getContext(), jumps, VPListener, OrdinaryVipFragment.this);
                rv_yaoxin_head.setAdapter(yaoXinHeadAdapter);

                rlOrdinaryVip.setVisibility(View.GONE);
                rlVip.setVisibility(View.GONE);
                rlSVip.setVisibility(View.VISIBLE);
                sdvSvipHead.setImageURI(PhoneUtil.getHead(d.getHeaderUrl()));
                tvSvipNickName.setText(d.getNickName());
//                tvOffectiveDate.setText("有效期至" + PhoneUtil.stampToDate((System.currentTimeMillis() + Long.parseLong(b.getExpired()) + "")));
                tvOffectiveDate.setText("有效期至" + d.getExpireTime());
                tvOffectiveDate.setVisibility(View.INVISIBLE);
                if (TextUtils.isEmpty(d.getInviteCode())) {
                    llInvitateCode.setVisibility(View.GONE);
                }
                tvCopyAddress.setText(d.getInviteCode());
                Map<String, String> map = new HashMap<>();
                OkHttpUtil.getJSON(getContext(), Constant.URL.member_profits, map, this);
                OkHttpUtil.getJSON(getContext(), Constant.URL.vips_invite_buttons, map, this);
                tv_head_des.setTextColor(Color.parseColor("#C59340"));
                //GET 开发完成 /modules/member/configurations 会员中心配置
                OkHttpUtil.getJSON(getContext(), Constant.URL.modules_member_configurations, map, this);
                //GET 开发中 /material/recommend/list 推荐素材列表
                pageNo = 1;
                nextIndex = 1;
                getDataSuCai();
                InviteFriend();

                //提现按钮
                tv_vip_tixian2.setTextColor(Color.parseColor("#C59340"));
                tv_vip_tixian2.setBackground(getResources().getDrawable(R.drawable.tixian));
                Drawable drawable = getResources().getDrawable(R.drawable.member_arrow_withdraw_svip);
/// 这一步必须要做,否则不会显示.
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                tv_vip_tixian2.setCompoundDrawables(null, null, drawable, null);
                if (b != null && b.getMerchant() != null && b.getMerchant().isShowSupplier()) {//供应商管理
                    ll_gysgl.setVisibility(View.VISIBLE);
                } else {
                    ll_gysgl.setVisibility(View.GONE);

                }
                break;
            }
        }

    }

    private void initHead(View inflate) {
        img=inflate.findViewById(R.id.img);
        tv_head_des=inflate.findViewById(R.id.tv_head_des);
        rv_yaoxin_head=inflate.findViewById(R.id.rv_yaoxin_head);
        view_head=inflate.findViewById(R.id.view_head);
        ll_yaoxin_head=inflate.findViewById(R.id.ll_yaoxin_head);
    }

    private void getDataSuCai() {
        Map<String, String> map = new HashMap<>();
        map.put("pageNo", pageNo + "");
        map.put("pageSize", pageSize + "");
        map.put("type", "2");


        OkHttpUtil.getJSON(getContext(), Constant.URL.material_recommend, map, this);


    }

    private void InviteFriend() {
        /**
         * 弹出好友邀请框根据有效期来判断
         * 如果默认返回"0",说明首次弹出邀请好友对话框
         * 2.如果不是首次，则获取上次保存的时间是否超过有效期，超过再次请求显示
         * 否则不显示
         */

        if (SharedPreferencesUtil.getLastInvitFriendTime(getActivity()).equals("0")) {
            OkHttpUtil.getJSON(getContext(), Constant.URL.adverts + "173000", this);
            Log.e("adverts", "----" + SharedPreferencesUtil.getLastInvitFriendTime(getActivity()));
        } else {
            long mills = Long.parseLong(SharedPreferencesUtil.getLastInvitFriendTime(getActivity()));
            Log.e("adverts", "mills=" + mills + " System.currentTimeMillis=" + System.currentTimeMillis());
            if (System.currentTimeMillis() > mills) {
                OkHttpUtil.getJSON(getContext(), Constant.URL.adverts + "173000", this);
            }
        }
    }

    private void dismissLoading() {
        if (loadingDialog != null) {
            loadingDialog.dismiss();
        }

        if (swipeRefreshLayout != null && swipeRefreshLayout.isRefreshing()) {
            swipeRefreshLayout.setRefreshing(false);
        }

        if (srl_include != null && srl_include.isRefreshing()) {
            srl_include.setRefreshing(false);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_shareFenSi: {//vip 列表邀请粉丝列表
                final String des= (String) v.getTag(R.id.itemTagDes);
                String positioninInnit = (String) v.getTag(R.id.itemTag);
                loadingDialog = LoadingDialog.newInstance("加载中");
                loadingDialog.show(getActivity().getFragmentManager(), "loading");
                String materialId = data.get((int) v.getTag()).getId();
                HashMap<String, String> hashMap = new HashMap<>();
                hashMap.put("materialId", materialId + "");
                //hashMap.put("needUpgradeVip", true + "");
                hashMap.put("upgrade", "3");
                if (!TextUtils.isEmpty(positioninInnit)) {
                    hashMap.put("number", positioninInnit + "");
                }


                OkHttpUtil.getJSON(getContext(), String.format(Constant.URL.material_posters, materialId), hashMap, new OkHttpUtil.OnDataListener() {
                    @Override
                    public void onResponse(String url, String json) {
                        if (!TextUtils.isEmpty(json)) {
                            LogeUtil.e("material_posters", json);
                            dismissLoading();
                            final VipSvipMaterialPosters material_postersEntity = gson.fromJson(json, VipSvipMaterialPosters.class);
                            if ("200".equals(material_postersEntity.getCode())) {

                                List<String> imgUrls = new ArrayList<>();
                                if (!TextUtils.isEmpty(material_postersEntity.getBody().getPoster())) {
                                    // imgUrls.add(material_postersEntity.getBody().getPoster());
                                }
                                if (material_postersEntity.getBody().getPosterList() != null) {
                                    for (int i = 0; i < material_postersEntity.getBody().getPosterList().size(); i++) {
                                        imgUrls.add(material_postersEntity.getBody().getPosterList().get(i).getUrl());

                                    }
                                }

                                VipSvipLijiyaoqingDialog vipSvipLijiyaoqingDialog = VipSvipLijiyaoqingDialog.newInstance(getContext(), imgUrls, material_postersEntity.getBody().getPoster(),des);
                                vipSvipLijiyaoqingDialog.show(getActivity().getFragmentManager());

                            } else {
                                ToastUtil.initToast(getContext(), material_postersEntity.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onFailure(String url, String error) {
                        dismissLoading();
                    }
                });
                break;
            }

            case R.id.tv_share0: {//vip 列表立即邀请按钮
                String positioninInnit = (String) v.getTag(R.id.itemTag);
                final String des= (String) v.getTag(R.id.itemTagDes);

                loadingDialog = LoadingDialog.newInstance("加载中");
                loadingDialog.show(getActivity().getFragmentManager(), "loading");
                String materialId = data.get((int) v.getTag()).getId();
                HashMap<String, String> hashMap = new HashMap<>();
                hashMap.put("materialId", materialId + "");
                //hashMap.put("needUpgradeVip", true + "");
                hashMap.put("upgrade", "1");
                if (!TextUtils.isEmpty(positioninInnit)) {
                    hashMap.put("number", positioninInnit + "");
                }


                OkHttpUtil.getJSON(getContext(), String.format(Constant.URL.material_posters, materialId), hashMap, new OkHttpUtil.OnDataListener() {
                    @Override
                    public void onResponse(String url, String json) {
                        if (!TextUtils.isEmpty(json)) {
                            LogeUtil.e("material_posters", json);
                            dismissLoading();
                            final VipSvipMaterialPosters material_postersEntity = gson.fromJson(json, VipSvipMaterialPosters.class);
                            if ("200".equals(material_postersEntity.getCode())) {

                                List<String> imgUrls = new ArrayList<>();
                                if (!TextUtils.isEmpty(material_postersEntity.getBody().getPoster())) {
                                    // imgUrls.add(material_postersEntity.getBody().getPoster());
                                }
                                if (material_postersEntity.getBody().getPosterList() != null) {
                                    for (int i = 0; i < material_postersEntity.getBody().getPosterList().size(); i++) {
                                        imgUrls.add(material_postersEntity.getBody().getPosterList().get(i).getUrl());

                                    }
                                }

                                VipSvipLijiyaoqingDialog vipSvipLijiyaoqingDialog = VipSvipLijiyaoqingDialog.newInstance(getContext(), imgUrls, material_postersEntity.getBody().getPoster(),des);
                                vipSvipLijiyaoqingDialog.show(getActivity().getFragmentManager());

                            } else {
                                ToastUtil.initToast(getContext(), material_postersEntity.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onFailure(String url, String error) {
                        dismissLoading();
                    }
                });
                break;
            }
            case R.id.tv_share1: {//svip 列表立即邀请按钮
                String positioninInnit = (String) v.getTag(R.id.itemTag);
                final String des= (String) v.getTag(R.id.itemTagDes);

                loadingDialog = LoadingDialog.newInstance("加载中");
                loadingDialog.show(getActivity().getFragmentManager(), "loading");
                String materialId = data.get((int) v.getTag()).getId();
                HashMap<String, String> hashMap = new HashMap<>();
                hashMap.put("materialId", materialId + "");
                //hashMap.put("needUpgradeVip", true + "");
                hashMap.put("upgrade", "2");
                if (!TextUtils.isEmpty(positioninInnit)) {
                    hashMap.put("number", positioninInnit + "");
                }

                OkHttpUtil.getJSON(getContext(), String.format(Constant.URL.material_posters, materialId), hashMap, new OkHttpUtil.OnDataListener() {
                    @Override
                    public void onResponse(String url, String json) {
                        if (!TextUtils.isEmpty(json)) {
                            LogeUtil.e("material_posters", json);
                            dismissLoading();
                            final VipSvipMaterialPosters material_postersEntity = gson.fromJson(json, VipSvipMaterialPosters.class);
                            if ("200".equals(material_postersEntity.getCode())) {

                                List<String> imgUrls = new ArrayList<>();
                                if (!TextUtils.isEmpty(material_postersEntity.getBody().getPoster())) {
                                    // imgUrls.add(material_postersEntity.getBody().getPoster());
                                }
                                if (material_postersEntity.getBody().getPosterList() != null) {
                                    for (int i = 0; i < material_postersEntity.getBody().getPosterList().size(); i++) {
                                        imgUrls.add(material_postersEntity.getBody().getPosterList().get(i).getUrl());

                                    }
                                }

                                VipSvipLijiyaoqingDialog vipSvipLijiyaoqingDialog = VipSvipLijiyaoqingDialog.newInstance(getContext(), imgUrls, material_postersEntity.getBody().getPoster(),des);
                                vipSvipLijiyaoqingDialog.show(getActivity().getFragmentManager());

                            } else {
                                ToastUtil.initToast(getContext(), material_postersEntity.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onFailure(String url, String error) {
                        dismissLoading();
                    }
                });
                break;
            }
            case R.id.iv_member_upgrade: {
//                InvitationCardDialog invitateCardDialog = InvitationCardDialog.newInstance(getContext());
//                invitateCardDialog.setListener(this);
//                invitateCardDialog.show(getActivity().getFragmentManager());
                /*fillInvitateCodeDialog = FillInvitateCodeDialog.newInstance(getContext());
                fillInvitateCodeDialog.setListener(this);
                fillInvitateCodeDialog.show(getActivity().getFragmentManager());*/

                VipYaoqingmashengjiPop vipYaoqingmashengjiPop = new VipYaoqingmashengjiPop(getContext(), getActivity());

                vipYaoqingmashengjiPop.setListener(this);
                vipYaoqingmashengjiPop.showPopupWindow();
                break;
            }

            case R.id.tv_upgrade: {

                isneewReflash = true;


                if (vipsNormal != null) {//普通升级
//按钮跳转类型 1 app 页面,2 app内部 webView链接,3 外部浏览器链接 4 微信小程序",
                    switch (vipsNormal.getBody().getBtn().getType()) {
                        case 1: {
                            if ("page/home".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/home";  首页

                                Intent intent1 = new Intent(getContext(), MainActivity.class);
                                intent1.putExtra("type", "page/home");
                                startActivity(intent1);


                            } else if ("page/home/material".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/home/material";  首页-动态(material)
                                Intent intent1 = new Intent(getContext(), MainActivity.class);

                                intent1.putExtra("type", "page/home/material");
                                startActivity(intent1);

                            } else if ("page/home/presell".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/home/presell";  首页-特卖(presell)
                                Intent intent1 = new Intent(getContext(), MainActivity.class);
                                intent1.putExtra("type", "page/home/presell");
                                startActivity(intent1);

                            } else if ("page/home/topic".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/home/topic";  首页-发现(topic)
                                Intent intent1 = new Intent(getContext(), MainActivity.class);
                                intent1.putExtra("type", "page/home/topic");
                                startActivity(intent1);

                            } else if ("page/village".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/village";  目的地列表页
                                Intent intent1 = new Intent(getContext(), MainActivity.class);

                                intent1.putExtra("type", "page/village");
                                startActivity(intent1);


                            } else if ("page/village/detail".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/village/detail";  目的地详情页
                                Intent intent1 = new Intent(getContext(), BourbonListActivity.class);

                                intent1.putExtra("villageId", vipsNormal.getBody().getBtn().getParams().getId());
                                intent1.putExtra("city", "");
                                intent1.putExtra("area", "");
                                startActivity(intent1);
                            } else if ("page/search".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/search";  房源搜索索引页

                                Intent intent1 = new Intent(getContext(), SearchBournActivity.class);
                                intent1.putExtra("cityId", vipsNormal.getBody().getBtn().getParams().getId());
                                startActivity(intent1);
                            } else if ("page/search/result".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/search/result";  房源搜索结果页
                                Intent intent1 = new Intent(getContext(), BourbonListActivity.class);
                                intent1.putExtra("villageId", vipsNormal.getBody().getBtn().getParams().getId());
                                intent1.putExtra("city", "");
                                intent1.putExtra("area", "");
                                startActivity(intent1);
                            } else if ("page/house/detail".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/house/detail";  房源详情页
                                //普通房源
                                Intent intent1 = new Intent(getContext(), HouseDetailsActivityFor3.class);
                                intent1.putExtra("houseId", vipsNormal.getBody().getBtn().getParams().getId());
                                intent1.putExtra("persellId", "");
//                    intent.putExtra("type", data.get(position).getType());
                                startActivity(intent1);

                            } else if ("page/presell/detail".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/presell/detail";  房源详情页
                                //特卖房源
                                Intent intent1 = new Intent(getContext(), HouseDetailsActivityFor3.class);
                                intent1.putExtra("houseId", vipsNormal.getBody().getBtn().getParams().getId());
                                intent1.putExtra("persellId", vipsNormal.getBody().getBtn().getParams().getId());
                                intent1.putExtra("presellProduct", true);
//                    intent.putExtra("type", data.get(position).getType());
                                startActivity(intent1);

                            } else if ("page/vip".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/vip";  VIP
                                Intent intent1 = new Intent(getContext(), MainActivity.class);
                                intent1.putExtra("type", "page/vip");
                                startActivity(intent1);

                            } else if ("page/vip/share".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/vip/share";  vip邀请好友分享页
                                startActivity(new Intent(getContext(), InviteFriendActivity.class));

                            } else if ("page/vip/draw".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/vip/draw";  vip提款页
                                startActivity(new Intent(getContext(), CashWithdrawalActivity.class));

                            } else if ("page/member".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/member";  我的
                                Intent intent1 = new Intent(getContext(), MainActivity.class);
                                intent1.putExtra("type", "page/member");
                                startActivity(intent1);

                            } else if ("page/member/order".equals(vipsNormal.getBody().getBtn().getUrl())) {
                                //"page/member/order";  我的订单

                                Intent intent1 = new Intent(getContext(), MyOrderDetailActivity.class);
                                intent1.putExtra("orderNo", vipsNormal.getBody().getBtn().getParams().getId());
                                startActivity(intent1);
                            }

                        }
                        break;
                        case 2: {
                            Intent intent = new Intent(getContext(), H5Activity.class);
                            intent.putExtra("title", vipsNormal.getBody().getBtn().getTitle());
                            intent.putExtra("url", vipsNormal.getBody().getBtn().getUrl());

                            startActivity(intent);
                        }
                        break;
                        case 3: {
                            Intent intent = new Intent();
                            intent.setAction("android.intent.action.VIEW");
                            Uri content_url = Uri.parse(vipsNormal.getBody().getBtn().getUrl());
                            intent.setData(content_url);
                            startActivity(intent);
                        }
                        break;
                        case 4: {
                            wxOpenApplet(vipsNormal.getBody().getBtn().getMiniAppId(), vipsNormal.getBody().getBtn().getUrl());

                        }
                        break;
                    }

                }

/*                fillInvitateCodeDialog = FillInvitateCodeDialog.newInstance(getContext());
                fillInvitateCodeDialog.setListener(this);
                fillInvitateCodeDialog.show(getActivity().getFragmentManager());*/
                // startActivityForResult(new Intent(getActivity(), UpgradeVipPaymentActivity.class), Constant.Code.upgradeVip);
                break;
            }

            case R.id.tv_see_svip_income: {  //查看SVIP收益
                startActivity(new Intent(getActivity(), SvipEquityActivity.class).putExtra("title", 1));
                break;
            }

            case R.id.tv_svip_withdrawl_btn: {
                if (TextUtils.isEmpty(refreshtoken.getBody().getMember().getMobile())) {
                    bindMobileDialog = BindMobileDialog.newInstance(getContext(), false);
                    bindMobileDialog.setListener(this);
                    bindMobileDialog.show(getActivity().getFragmentManager());
                } else {
                    startActivityForResult(new Intent(getActivity(), CashWithdrawalActivity.class), Constant.Code.Draw_Cash);
                }
                break;
            }

            case R.id.tv_svipnamefor3: {
                startActivityForResult(new Intent(getActivity(), SvipSetNameActivity.class), Constant.Code.NickName);

            }
            break;
            case R.id.tv_svipname: {
                startActivityForResult(new Intent(getActivity(), SvipSetNameActivity.class), Constant.Code.NickName);
                break;
            }

            case R.id.tv_read_more: { //我的收益(查看更多详情)
                startActivity(new Intent(getActivity(), IncomeDetailsActivity.class).putExtra("income", totalIncmome));
                break;
            }

            case R.id.ll_custome_layout: {  //客户列表
                startActivityForResult(new Intent(getActivity(), CustomerListActivity.class).putExtra("memberType", "1"), Constant.Code.SvipCode);
            }
            break;

            case R.id.tv_customer_action: {  //客户行为
                startActivity(new Intent(getActivity(), CustomerBehaviorActivity.class));
            }
            break;

            case R.id.tv_customer_order: {//客户订单
                startActivity(new Intent(getActivity(), CustomerOrderActivity.class).putExtra("vipOrderType", "0"));
            }
            break;

          /*       case R.id.tv_setting: { //分佣设置
                startActivity(new Intent(getActivity(), CommissionSettingActivity.class));
                break;
            }*/
        }
    }

    @OnClick({R.id.tv_svip_myShop, R.id.img_chakanshouyi0, R.id.img_chakanshouyi, R.id.ll_yqsvip, R.id.ll_yqsvipdown, R.id.ll_yqvipdown, R.id.ll_yqvip, R.id.tv_performance_list, R.id.tv_vip_performance_list, R.id.ll_svip_custome_layout, R.id.tv_copy_code, R.id.tv_copy_code_vip, R.id.tv_svip_customer_action
            , R.id.tv_svip_customer_order, R.id.tv_commsion, R.id.tv_vip_withdrawl, R.id.tv_see_vip_income, R.id.tv_svip_read_more
            , R.id.tv_svip_invitate_friend, R.id.tv_vip_invitate_friend, R.id.ll_lower_level_layout, R.id.ll_vip_lower_level_layout, R.id.iv_vip_upgrade, R.id.ll_fission_red_envelope
            , R.id.tv_wdjd, R.id.tv_dqrdd, R.id.tv_qbdd, R.id.tv_more})
    public void onClickView(View v) {
        switch (v.getId()) {
            case R.id.tv_wdjd://我的酒店

                  startActivity(new Intent(getContext(), MyWineShopActivity.class));

                break;
            case R.id.tv_dqrdd://待确认订单


            {
               // ToastUtil.initToast(getContext(), "即将上线");
                Intent intent1 = new Intent(getContext(), ShopActivity.class);
                intent1.putExtra("position", 0);
                startActivity(intent1);


            }
            break;
            case R.id.tv_qbdd://全部订单

            {
                //ToastUtil.initToast(getContext(), "即将上线");

                Intent intent1 = new Intent(getContext(), ShopActivity.class);
                intent1.putExtra("position", 3);
                startActivity(intent1);
            }
            break;
            case R.id.tv_more://更多
                HuiYuanMorePop huiYuanMorePop = new HuiYuanMorePop(getContext(), getActivity());
                huiYuanMorePop.showPopupWindow();
                break;
            case R.id.tv_svip_myShop: {//我的店铺
                if (merchant_shareEntity != null) {
                    wxOpenApplet(merchant_shareEntity.getBody().getMiniAppId(), merchant_shareEntity.getBody().getPath());

                }

                break;
            }

            case R.id.img_chakanshouyi://我的收益 帮助
                loadingDialog = LoadingDialog.newInstance("请求中...");
                loadingDialog.show(getActivity().getFragmentManager());
                OkHttpUtil.getJSON(getContext(), Constant.URL.global_configurations, this);


                break;
            case R.id.img_chakanshouyi0://我的收益 帮助
                loadingDialog = LoadingDialog.newInstance("请求中...");
                loadingDialog.show(getActivity().getFragmentManager());
                OkHttpUtil.getJSON(getContext(), Constant.URL.global_configurations, this);
                break;
            case R.id.ll_yqsvip: {//svip礼包
               /* Intent intent = new Intent(getActivity(), SVIPLibaoAndFreeActivity.class);
                intent.putExtra("type", 0);
                startActivity(intent);*/
                startActivity(new Intent(getContext(), SVIPFreeActivity.class));


                isneewReflash = true;
            }
            break;
            case R.id.ll_yqsvipdown: {//svip免费
               /* Intent intent = new Intent(getActivity(), SVIPLibaoAndFreeActivity.class);
                intent.putExtra("type",1);
                startActivity(intent);*/

                startActivity(new Intent(getContext(), InviteDownloadActivity.class));

                isneewReflash = true;

            }
            break;
            case R.id.ll_yqvip: {//邀请VIP
                startActivity(new Intent(getContext(), InviteLiBaoActivity.class));

                isneewReflash = true;
            }
            break;
            case R.id.ll_yqvipdown: {//邀请下载APP
                startActivity(new Intent(getContext(), InviteDownloadActivity.class));

                isneewReflash = true;

            }
            break;
            case R.id.iv_vip_upgrade: //查看推荐人
                /*           if (refreshtoken.getBody().getMember().getParent() != null) {*/
                SeeRecommerVipDialog seeRecommerVipDialog = SeeRecommerVipDialog.newInstance(getActivity(), refreshtoken.getBody().getMember().getParent().getHeaderUrl(), refreshtoken.getBody().getMember().getParent().getNickName());
                seeRecommerVipDialog.show(getActivity().getFragmentManager());
              /*  } else {
                    fillInvitateCodeDialog = FillInvitateCodeDialog.newInstance(getContext());
                    fillInvitateCodeDialog.setListener(this);
                    fillInvitateCodeDialog.show(getActivity().getFragmentManager());
                }*/
                break;

            case R.id.tv_performance_list: {//vip业绩列表
                startActivity(new Intent(getActivity(), PerformanceListActivity.class));
            }
            break;

            case R.id.tv_vip_performance_list: {//vip业绩列表
                startActivity(new Intent(getActivity(), PerformanceListActivity.class));
            }
            break;

            case R.id.ll_svip_custome_layout: { //svip我的客户
                startActivityForResult(new Intent(getActivity(), CustomerListActivity.class).putExtra("memberType", "1"), Constant.Code.SvipCode);
//                startActivity(new Intent(getActivity(), CustomerListSvipActivity.class));
            }
            break;

            case R.id.tv_copy_code: { //svip复制地址
                PhoneUtil.copyBoard(getActivity(), tvCopyAddress.getText().toString());
            }
            break;

            case R.id.tv_copy_code_vip: {
                PhoneUtil.copyBoard(getActivity(), tvCopyAddressVip.getText().toString());
            }
            break;
            case R.id.tv_svip_customer_action: {//svip客户行为
                startActivity(new Intent(getActivity(), CustomerBehaviorActivity.class));
            }
            break;

            case R.id.tv_svip_customer_order: {
                startActivity(new Intent(getActivity(), CustomerOrderActivity.class).putExtra("vipOrderType", "1"));
            }
            break;

            case R.id.ll_lower_level_layout: {//SVIP我的团队
                startActivity(new Intent(getActivity(), CustomerListActivity.class).putExtra("memberType", "2").putExtra("shareBean", gson.toJson(refreshtoken.getBody().getMember().getInviteShare())));
            }
            break;
            case R.id.ll_vip_lower_level_layout: {//VIP我的团队
                startActivity(new Intent(getActivity(), CustomerListActivity.class).putExtra("memberType", "3").putExtra("shareBean", gson.toJson(refreshtoken.getBody().getMember().getInviteShare())));

            }
            break;

            case R.id.tv_commsion: {
                startActivity(new Intent(getActivity(), CommissionSettingActivity.class));
            }
            break;

            case R.id.tv_vip_withdrawl: {
                if (TextUtils.isEmpty(refreshtoken.getBody().getMember().getMobile())) {
                    bindMobileDialog = BindMobileDialog.newInstance(getContext(), false);
                    bindMobileDialog.setListener(this);
                    bindMobileDialog.show(getActivity().getFragmentManager());
                } else {
                    startActivityForResult(new Intent(getActivity(), CashWithdrawalActivity.class), Constant.Code.Draw_Cash);
                }
            }
            break;

            case R.id.tv_see_vip_income: {
                startActivity(new Intent(getActivity(), SvipEquityActivity.class).putExtra("title", 0));
                break;
            }

            case R.id.tv_svip_read_more: {
                startActivity(new Intent(getActivity(), IncomeDetailsActivity.class).putExtra("income", totalIncmome));
                break;
            }

            case R.id.tv_vip_invitate_friend://VIP
                //startActivity(new Intent(getContext(), InviteDownloadActivity.class));

                break;
            case R.id.tv_svip_invitate_friend://svip


        /*        ShareDialog shareDialog = ShareDialog.newInstance();
                shareDialog.show(getActivity().getFragmentManager());
                shareDialog.setOnItemClickListener(new BaseDialog.OnItemClickListener() {
                    @Override
                    public void onItemClick(View v) {
                        switch (v.getId()) {
                            case R.id.tv_Swx: {
                                saveImageToSdCard(getActivity(), refreshtoken.getBody().getMember().getInviteShare().getImageURL());
                                share(0);
                            }
                            break;
                            case R.id.tv_Spyq: {
                                saveImageToSdCard(getActivity(), refreshtoken.getBody().getMember().getInviteShare().getImageURL());
                                share(1);

                            }
                            break;
                            case R.id.tv_Ssave: {
                                saveImageToSdCard(getActivity(), refreshtoken.getBody().getMember().getInviteShare().getImageURL());
                                share(2);
                            }
                            break;
                        }
                    }
                });


*/


                startActivity(new Intent(getActivity(), InviteFriendActivity.class));

                break;

            case R.id.ll_fission_red_envelope: {
                if (mp2 != null) {
                    Intent intent = new Intent(getActivity(), FissionRedEnvelopeActivity.class);
                    intent.putExtra("allowFission", mp2.getBody().isAllowFission());
                    intent.putExtra("fissionPercent", mp2.getBody().getFissionPercent());
                    intent.putExtra("fissionImageUrl", mp2.getBody().getFissionImageUrl());
                    startActivityForResult(intent, Constant.Code.FissionRedEnvelope);
                }
            }
            break;
        }
    }


    @Override
    public void onItemClick(View v) {
        switch (v.getId()) {
            case R.id.btn_confirm: {
                if (TextUtils.isEmpty(refreshtoken.getBody().getMember().getMobile())) {
                    if (bindMobileDialog == null)
                        bindMobileDialog = BindMobileDialog.newInstance(getActivity(), false);
                    bindMobileDialog.setListener(this);
                    bindMobileDialog.show(getActivity().getFragmentManager());
                }
                break;


            }


        }
    }

    @Override
    public void finishBindMobile(String phone, String code, boolean isUpgradeVip) {
        this.isUpgradeVip = isUpgradeVip;
        loadingDialog = LoadingDialog.newInstance("绑定中...");
        loadingDialog.show(getActivity().getFragmentManager());
        Map<String, Object> map = new HashMap<>();
        OkHttpUtil.postJson(getActivity(), Constant.URL.members, new members(1, phone, code), map, this);
    }

    @Override
    public void unBindMobile() {
        isUpgradeVip = false;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == Constant.Code.NickName) {
            if (resultCode == getActivity().RESULT_OK) {
                getData();
            }
        } else if (requestCode == Constant.Code.Draw_Cash) {
            if (resultCode == getActivity().RESULT_OK) {
                Map<String, String> map = new HashMap<>();
                OkHttpUtil.getJSON(getContext(), Constant.URL.vips_invite_buttons, map, this);
                OkHttpUtil.getJSON(getContext(), Constant.URL.member_profits, map, this);

            }
        } else if (requestCode == Constant.Code.upgradeVip) {
            if (resultCode == getActivity().RESULT_OK) {
                isUpgradeVip = true;

                getData();
            }
        } else if (requestCode == Constant.Code.SvipCode) {
            if (resultCode == Activity.RESULT_OK) {
                if (VPListener != null) {
                    VPListener.vipJump();
                }
            }
        } else if (requestCode == Constant.Code.FissionRedEnvelope) {
            Map<String, String> map = new HashMap<>();
            OkHttpUtil.getJSON(getContext(), Constant.URL.member_profits, map, this);
        }

    }

    public void checkToken() {
        Map<String, Object> map = new HashMap<>();
        OkHttpUtil.postJson(getActivity(), Constant.URL.refresh_token, null, map, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                if (!TextUtils.isEmpty(json)) {
                    if (Constant.URL.refresh_token.equals(url)) { //刷新Token
                        LogeUtil.e("refresh_token", json);
                        RefreshtokenEntity refreshtoken = gson.fromJson(json, RefreshtokenEntity.class);

                        if (Constant.Strings.SUC.equals(refreshtoken.getCode())) {
                            //改变 主页bottom vip 图标及文字颜色
                            mRxManager.post(getResources().getString(R.string.ChangeMainBotton_vip_dirwableAndColor), refreshtoken.getBody().getMember().getType());
                            SharedPreferencesUtil.saveRoleInfo(getActivity(), json);
                            SharedPreferencesUtil.saveToken(getContext(), refreshtoken.getBody().getToken());
                            if (!refreshtoken.getBody().getMember().getType().equals(SharedPreferencesUtil.getRoleInfo(getContext()).getMember().getType())) {
                                getData();
                            }

                        }
                    }
                }
            }

            @Override
            public void onFailure(String url, String error) {

            }
        });
    }

    @Override
    public void onRefresh() {
        getData();
    }

    private void share(int i) {
        String imageFileName = IMAGE_NAME + ".jpg";
        File externalCacheDir = getActivity().getExternalCacheDir();
        String fileName = externalCacheDir.getPath() + "/" + imageFileName;
        String sharefileName = externalCacheDir.getPath() + "/12306" + imageFileName;
        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = refreshtoken.getBody().getMember().getInviteShare().getLinkURL();
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = refreshtoken.getBody().getMember().getInviteShare().getTitle();
        msg.description = refreshtoken.getBody().getMember().getInviteShare().getDesc();
        Bitmap bitmap = BitMapUtil.getBitmap(fileName);
        /*Bitmap bitmap1 = BitMapUtil.compressBitmap(bitmap, 31*1024);
        BitMapUtil.saveBitmap2File(bitmap1,sharefileName);
        Bitmap bitmap2 = BitMapUtil.getBitmap(sharefileName);*/
        //Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.share);
        msg.thumbData = BitMapUtil.compressBitmap(bitmap, 31 * 1024);
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = "webpage";
        req.message = msg;
        req.scene = i == 0 ? SendMessageToWX.Req.WXSceneSession : i == 1 ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneFavorite;
        IWXAPI api = WXAPIFactory.createWXAPI(getActivity(), Constant.ID.WeChat_APP_ID, false);
        api.sendReq(req);

    }

    public static String IMAGE_NAME = "shareVip";

    //根据网络图片url路径保存到本地
    public File saveImageToSdCard(Context context, String image) {
        boolean success = false;
        File file = null;
        try {
            file = createStableImageFile(context);
            Bitmap bitmap = null;
            URL url = new URL(image);
            HttpURLConnection conn = null;
            conn = (HttpURLConnection) url.openConnection();
            InputStream is = null;
            is = conn.getInputStream();
            bitmap = BitmapFactory.decodeStream(is);
            FileOutputStream outStream;

            outStream = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
            outStream.flush();
            outStream.close();
            success = true;
            //MediaStore.Images.Media.insertImage(context.getContentResolver(), image, file.getName(), "你对图片的描述");

        } catch (Exception e) {
            e.printStackTrace();
        }

        if (success) {

            return file;
        } else {
            return null;
        }
    }

    //创建本地保存路径
    public static File createStableImageFile(Context context) throws IOException {
        String imageFileName = IMAGE_NAME + System.currentTimeMillis() + ".jpg";
        File storageDir = context.getExternalCacheDir();
        File image = new File(storageDir, imageFileName);
        return image;
    }


    public OnViplPageListener VPListener;

    public interface OnViplPageListener {
        public void vipJump();
    }

    public void setOnControlPageListener(OnViplPageListener listener) {
        this.VPListener = listener;
    }


    /**
     * APP打开小程序
     */
    public void wxOpenApplet(String userName, String path) {
        IWXAPI api = WXAPIFactory.createWXAPI(getContext(), Constant.ID.WeChat_APP_ID);
        if (!api.isWXAppInstalled()) {//未安装微信
            ToastUtil.initToast(getContext(), "您未安装微信");
            return;
        }
        WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
        req.userName = userName; // 填小程序原始id
        req.path = path;                  //拉起小程序页面的可带参路径，不填默认拉起小程序首页
        req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版，体验版和正式版
        api.sendReq(req);
    }

    /**
     * APP打开小程序
     */
    public void wxOpenApplet(String userName, String path, int miniProgramType) {
        IWXAPI api = WXAPIFactory.createWXAPI(getContext(), Constant.ID.WeChat_APP_ID);
        if (!api.isWXAppInstalled()) {//未安装微信
            ToastUtil.initToast(getContext(), "您未安装微信");
            return;

        }
        WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
        req.userName = userName; // 填小程序原始id
        req.path = path;                  //拉起小程序页面的可带参路径，不填默认拉起小程序首页
        //      "miniProgramType": "integer,小程序版本，1：开发版 2：预览版 3：正式版，jumpType为3时必然存在"
        if (miniProgramType == 1) {
            req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_TEST;// 可选打开 开发版，体验版和正式版

        } else if (miniProgramType == 2) {
            req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_PREVIEW;// 可选打开 开发版，体验版和正式版

        } else if (miniProgramType == 3) {
            req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版，体验版和正式版

        }

        api.sendReq(req);
    }

    /**
     * 界面跳转邀请输入框
     */
    public void openInvitateDialog(int status) {
        if (status == 1) {
            mark = 1;
        } else {
            tvWriteCode.performClick();
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        if (animation != null) {
            animation.cancel();
        }
    }

    //广告位
    public class VipMidAdvAdapter extends PagerAdapter {

        private List<SimpleDraweeView> imgData;
        private Jumps jumps;
        private OnViplPageListener vpListener;

        public VipMidAdvAdapter(Jumps jumps, OnViplPageListener vpListener) {

            this.jumps = jumps;
            this.vpListener = vpListener;
        }

        public void setData(List<MemberConfigurations.BodyBean.MiddleAdvertsBean> data) {
            if (imgData == null) {
                imgData = new ArrayList<>();
            } else {
                imgData.clear();
            }
            if (navView == null) {
                return;
            }
            navView.setCount(data.size());
            if (data.size() > 1) {
                imgData.add(initSDV(data.get(data.size() - 1).getJumpType(), data.get(data.size() - 1).getUrl(), jumps, vpListener, data.get(data.size() - 1).getMiniAppId(), data.get(data.size() - 1).getMiniProgramType(), data.size() - 1, data.get(data.size() - 1).getMaterial().getUrl()));
            }
            for (int i = 0; i < data.size(); i++) {
                imgData.add(initSDV(data.get(i).getJumpType(), data.get(i).getUrl(), jumps, vpListener, data.get(i).getMiniAppId(), data.get(i).getMiniProgramType(), i, data.get(i).getMaterial().getUrl()));
            }
            if (data.size() > 1) {
                imgData.add(initSDV(data.get(0).getJumpType(), data.get(0).getUrl(), jumps, vpListener, data.get(0).getMiniAppId(), data.get(0).getMiniProgramType(), 0, data.get(0).getMaterial().getUrl()));
            }
            this.notifyDataSetChanged();
        }


        public SimpleDraweeView initSDV(final int JumpType, final String url, final OrdinaryVipFragment.Jumps jumps, final OrdinaryVipFragment.OnViplPageListener VPListener, final String MiniAppId, final int MiniProgramType, final int index, String imgurl) {
            final SimpleDraweeView sdv = (SimpleDraweeView) LayoutInflater.from(getContext())
                    .inflate(R.layout.sdv_home_vip, null, false);
            sdv.setAspectRatio(5.4F);
            sdv.setImageURI(Uri.parse(imgurl));
            sdv.setTag(index);
            // sdv.setOnClickListener(HomeFragment.this);
            sdv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    JumpUtils.jump(getContext(), JumpType, url, jumps, VPListener, MiniAppId, MiniProgramType);
                }
            });

            return sdv;
        }

        @Override
        public int getCount() {
            if (imgData == null) {
                return 0;
            }
            return imgData.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(imgData.get(position));
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(imgData.get(position));
            return imgData.get(position);
        }


    }

    @Override
    public boolean onBackPressed() {
        if (vImageWatcher == null) {
            return false;
        } else {
            // 当确认没有子Fragmnt时可以直接return false
            if (!vImageWatcher.handleBackPressed()) {
                return BackHandlerHelper.handleBackPress(this);
            } else {
                return !BackHandlerHelper.handleBackPress(this);
            }
        }


    }

    @OnClick({R.id.tv_vip_shouyidetical, R.id.ll_yue, R.id.ll_vip_yongjin, R.id.ll_vip_fs, R.id.ll_vip_vip, R.id.ll_vip_svip, R.id.ll_vip_des, R.id.ll_top, R.id.tv_vip_copy, R.id.tv_vip_myStore, R.id.tv_vip_tixian1,
            R.id.img_vip_yaoqing, R.id.tv_vip_tixian2,
            R.id.tv_vip_dingdan
            , R.id.tv_vip_kehuxingwei, R.id.tv_vip_yejiliebiao, R.id.tv_vip_fenyongshezhi})
    public void onClickViews(View v) {
        switch (v.getId()) {
            case R.id.ll_yue://我的余额
                startActivity(new Intent(getContext(), MyBalanceActivity.class));
                break;
            case R.id.ll_top://顶部广告位

                if (headerAdverts != null && headerAdverts.size() > 0) {
                    wxOpenApplet(headerAdverts.get(0).getMiniAppId(), headerAdverts.get(0).getUrl());

                }
                break;
            case R.id.tv_vip_copy://copy邀请码
                if (refreshtoken != null && refreshtoken.getBody() != null && refreshtoken.getBody().getMember() != null && refreshtoken.getBody().getMember().getInviteCode() != null) {
                    PhoneUtil.copyBoard(getActivity(), refreshtoken.getBody().getMember().getInviteCode());

                }
                break;
            case R.id.tv_vip_myStore://我的店铺
                if (merchant_shareEntity != null) {
                    wxOpenApplet(merchant_shareEntity.getBody().getMiniAppId(), merchant_shareEntity.getBody().getPath());

                }
                break;
            case R.id.ll_vip_yongjin:

            case R.id.tv_vip_tixian1://加返佣金
              /*  if (mp2 != null && mp2.getBody() != null && mp2.getBody().getAddBrokeragePage() != null) {
                    memberProfitsEntity.BodyBean.AddBrokeragePageBean addBrokeragePage = mp2.getBody().getAddBrokeragePage();
                    wxOpenApplet(addBrokeragePage.getMiniAppId(), addBrokeragePage.getUrl());

                }*/
                startActivity(new Intent(getContext(), JiaFanActivity.class));


                break;
            case R.id.img_vip_yaoqing://邀请
            case R.id.ll_vip_des:
                //拿到 appbar 的 behavior,让 appbar 滚动
                ViewGroup.LayoutParams layoutParams = appBarLayout.getLayoutParams();
                CoordinatorLayout.Behavior behavior =
                        ((CoordinatorLayout.LayoutParams) layoutParams).getBehavior();
                if (behavior instanceof AppBarLayout.Behavior) {
                    AppBarLayout.Behavior appBarLayoutBehavior = (AppBarLayout.Behavior) behavior;


                    //注意传递负值
                    appBarLayoutBehavior.setTopAndBottomOffset((int) -(appBarLayout.getHeight() - tv_title.getHeight()));

                    srl_include.setEnabled(false);
                    tv_title.setAlpha(1);
                }


                break;
            case R.id.tv_vip_shouyidetical:
                startActivity(new Intent(getActivity(), IncomeDetailsActivity.class).putExtra("income", totalIncmome));

                break;
            /*case R.id.ll_vip_shouyidetical://收益详情
                startActivity(new Intent(getActivity(), IncomeDetailsActivity.class).putExtra("income", totalIncmome));

                break;*/
            case R.id.tv_vip_tixian2://提现
                if (TextUtils.isEmpty(refreshtoken.getBody().getMember().getMobile())) {
                    bindMobileDialog = BindMobileDialog.newInstance(getContext(), false);
                    bindMobileDialog.setListener(this);
                    bindMobileDialog.show(getActivity().getFragmentManager());
                } else {
                    startActivityForResult(new Intent(getActivity(), CashWithdrawalActivity.class), Constant.Code.Draw_Cash);
                }
                break;

           /* case R.id.tv_vip_lijichakan://团队
                startActivity(new Intent(getActivity(), CustomerListActivity.class).putExtra("memberType", "2").putExtra("shareBean", gson.toJson(refreshtoken.getBody().getMember().getInviteShare())));

                break;*/
            case R.id.tv_vip_dingdan://客户订单
                startActivity(new Intent(getActivity(), CustomerOrderActivity.class).putExtra("vipOrderType", "1"));

                break;
            case R.id.tv_vip_kehuxingwei://客户行为
                startActivity(new Intent(getActivity(), CustomerBehaviorActivity.class));

                break;
            case R.id.tv_vip_yejiliebiao://业绩列表
                startActivity(new Intent(getActivity(), PerformanceListActivity.class));

                break;
            case R.id.tv_vip_fenyongshezhi://分佣设置
                startActivity(new Intent(getActivity(), CommissionSettingActivity.class));

                break;

            case R.id.ll_vip_svip://svip
                startActivity(new Intent(getActivity(), CustomerListActivity.class).putExtra("memberType", "2").putExtra("shareBean", gson.toJson(refreshtoken.getBody().getMember().getInviteShare())));

                break;

            case R.id.ll_vip_vip://vip
                startActivity(new Intent(getActivity(), CustomerListActivity.class).putExtra("memberType", "2").putExtra("shareBean", gson.toJson(refreshtoken.getBody().getMember().getInviteShare())));

                break;

            case R.id.ll_vip_fs://粉丝
                startActivityForResult(new Intent(getActivity(), CustomerListActivity.class).putExtra("memberType", "1"), Constant.Code.SvipCode);

                break;


        }
    }
}
